mirror of
https://github.com/Vale54321/schafkop-neu.git
synced 2025-12-11 09:59:33 +01:00
delete back and frontend
add schafkopf os add build firmware action
This commit is contained in:
66
.github/workflows/BuildAndPushContainer.yml
vendored
66
.github/workflows/BuildAndPushContainer.yml
vendored
@@ -1,66 +0,0 @@
|
||||
name: Build and Push Docker Image
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
IMAGE_NAME: ${{ github.repository }}/app
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: [self-hosted]
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Extract metadata (tags, labels)
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
tags: |
|
||||
type=raw,value=latest,enable={{is_default_branch}}
|
||||
type=sha,format=short
|
||||
type=ref,event=branch
|
||||
|
||||
- name: Build and push Docker image (multi-arch)
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
push: true
|
||||
platforms: linux/amd64,linux/arm64
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
build-args: |
|
||||
NODE_VERSION=20-bookworm-slim
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
- name: Notify updater (GET, bearer)
|
||||
if: ${{ success() && github.ref == 'refs/heads/main' }}
|
||||
env:
|
||||
WEBHOOK_TOKEN: ${{ secrets.WEBHOOK_TOKEN }}
|
||||
run: |
|
||||
curl -fsS --retry 5 -H "Authorization: Bearer ${WEBHOOK_TOKEN}" http://10.0.3.185:8080/v1/update
|
||||
100
.github/workflows/build-firmware.yml
vendored
Normal file
100
.github/workflows/build-firmware.yml
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
name: Build Firmware
|
||||
|
||||
on:
|
||||
push:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
env:
|
||||
BRANCH_RAW: ${{ github.ref_name }}
|
||||
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ./pico
|
||||
|
||||
steps:
|
||||
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cache/pip
|
||||
~/.platformio/.cache
|
||||
key: ${{ runner.os }}-pio
|
||||
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
- name: Install PlatformIO Core
|
||||
run: pip install --upgrade platformio
|
||||
|
||||
- name: Build PlatformIO Project
|
||||
run: pio run
|
||||
|
||||
- name: Compute branch slug & tag
|
||||
id: meta
|
||||
run: |
|
||||
set -euo pipefail
|
||||
slug="$BRANCH_RAW"
|
||||
# Replace anything not [A-Za-z0-9._-] with '-'
|
||||
slug="${slug//[^A-Za-z0-9._-]/-}"
|
||||
# Trim to 60 chars (tags can be long, but keep it tidy)
|
||||
slug="${slug:0:60}"
|
||||
# Avoid trailing dots or dashes
|
||||
slug="${slug%-}"
|
||||
slug="${slug%.}"
|
||||
echo "slug=$slug" >> "$GITHUB_OUTPUT"
|
||||
echo "tag=nightly-$slug" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Ensure rolling prerelease exists (create if missing)
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
TAG="${{ steps.meta.outputs.tag }}"
|
||||
if gh release view "$TAG" >/dev/null 2>&1; then
|
||||
echo "Release $TAG exists — make sure tag points to this commit"
|
||||
git config user.email "actions@github.com"
|
||||
git config user.name "GitHub Actions"
|
||||
git fetch --tags --force
|
||||
git tag -f "$TAG" "$GITHUB_SHA"
|
||||
git push --force origin "refs/tags/$TAG"
|
||||
# Make sure it remains a prerelease
|
||||
gh release edit "$TAG" --prerelease --title "Nightly ($BRANCH_RAW)"
|
||||
else
|
||||
gh release create "$TAG" \
|
||||
--title "Nightly ($BRANCH_RAW)" \
|
||||
--notes "Latest successful build of branch: $BRANCH_RAW" \
|
||||
--prerelease
|
||||
fi
|
||||
|
||||
- name: Attach/overwrite assets
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
TAG="${{ steps.meta.outputs.tag }}"
|
||||
|
||||
# Optional: write a tiny manifest for fast comparisons on the device
|
||||
mkdir -p .nightly
|
||||
cat > .nightly/manifest.json <<EOF
|
||||
{
|
||||
"branch": "${BRANCH_RAW}",
|
||||
"tag": "${TAG}",
|
||||
"commit": "${GITHUB_SHA}",
|
||||
"built_at": "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
||||
}
|
||||
EOF
|
||||
|
||||
# Upload and overwrite ( --clobber ) to keep filenames stable
|
||||
gh release upload "$TAG" \
|
||||
.pio/build/pico/firmware.uf2 \
|
||||
.nightly/manifest.json \
|
||||
--clobber
|
||||
56
backend/.gitignore
vendored
56
backend/.gitignore
vendored
@@ -1,56 +0,0 @@
|
||||
# compiled output
|
||||
/dist
|
||||
/node_modules
|
||||
/build
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
pnpm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
|
||||
# Tests
|
||||
/coverage
|
||||
/.nyc_output
|
||||
|
||||
# IDEs and editors
|
||||
/.idea
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
|
||||
# IDE - VSCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# temp directory
|
||||
.temp
|
||||
.tmp
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all"
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
<p align="center">
|
||||
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
|
||||
</p>
|
||||
|
||||
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
|
||||
[circleci-url]: https://circleci.com/gh/nestjs/nest
|
||||
|
||||
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
|
||||
<p align="center">
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
|
||||
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
|
||||
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
|
||||
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
|
||||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
|
||||
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a>
|
||||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
|
||||
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a>
|
||||
</p>
|
||||
<!--[](https://opencollective.com/nest#backer)
|
||||
[](https://opencollective.com/nest#sponsor)-->
|
||||
|
||||
## Description
|
||||
|
||||
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
|
||||
|
||||
## Project setup
|
||||
|
||||
```bash
|
||||
$ npm install
|
||||
```
|
||||
|
||||
## Compile and run the project
|
||||
|
||||
```bash
|
||||
# development
|
||||
$ npm run start
|
||||
|
||||
# watch mode
|
||||
$ npm run start:dev
|
||||
|
||||
# production mode
|
||||
$ npm run start:prod
|
||||
```
|
||||
|
||||
## Run tests
|
||||
|
||||
```bash
|
||||
# unit tests
|
||||
$ npm run test
|
||||
|
||||
# e2e tests
|
||||
$ npm run test:e2e
|
||||
|
||||
# test coverage
|
||||
$ npm run test:cov
|
||||
```
|
||||
|
||||
## Deployment
|
||||
|
||||
When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the [deployment documentation](https://docs.nestjs.com/deployment) for more information.
|
||||
|
||||
If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:
|
||||
|
||||
```bash
|
||||
$ npm install -g @nestjs/mau
|
||||
$ mau deploy
|
||||
```
|
||||
|
||||
With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.
|
||||
|
||||
## Resources
|
||||
|
||||
Check out a few resources that may come in handy when working with NestJS:
|
||||
|
||||
- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework.
|
||||
- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy).
|
||||
- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/).
|
||||
- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks.
|
||||
- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com).
|
||||
- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com).
|
||||
- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs).
|
||||
- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com).
|
||||
|
||||
## Support
|
||||
|
||||
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
|
||||
|
||||
## Stay in touch
|
||||
|
||||
- Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec)
|
||||
- Website - [https://nestjs.com](https://nestjs.com/)
|
||||
- Twitter - [@nestframework](https://twitter.com/nestframework)
|
||||
|
||||
## License
|
||||
|
||||
Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE).
|
||||
@@ -1,34 +0,0 @@
|
||||
// @ts-check
|
||||
import eslint from '@eslint/js';
|
||||
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
|
||||
import globals from 'globals';
|
||||
import tseslint from 'typescript-eslint';
|
||||
|
||||
export default tseslint.config(
|
||||
{
|
||||
ignores: ['eslint.config.mjs'],
|
||||
},
|
||||
eslint.configs.recommended,
|
||||
...tseslint.configs.recommendedTypeChecked,
|
||||
eslintPluginPrettierRecommended,
|
||||
{
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.node,
|
||||
...globals.jest,
|
||||
},
|
||||
sourceType: 'commonjs',
|
||||
parserOptions: {
|
||||
projectService: true,
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
rules: {
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-floating-promises': 'warn',
|
||||
'@typescript-eslint/no-unsafe-argument': 'warn'
|
||||
},
|
||||
},
|
||||
);
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/nest-cli",
|
||||
"collection": "@nestjs/schematics",
|
||||
"sourceRoot": "src",
|
||||
"compilerOptions": {
|
||||
"deleteOutDir": true
|
||||
}
|
||||
}
|
||||
10549
backend/package-lock.json
generated
10549
backend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,73 +0,0 @@
|
||||
{
|
||||
"name": "backend",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"author": "",
|
||||
"private": true,
|
||||
"license": "UNLICENSED",
|
||||
"scripts": {
|
||||
"build": "nest build",
|
||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||
"start": "nest start",
|
||||
"start:dev": "nest start --watch",
|
||||
"start:debug": "nest start --debug --watch",
|
||||
"start:prod": "node dist/main",
|
||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^11.0.1",
|
||||
"@nestjs/core": "^11.0.1",
|
||||
"@nestjs/platform-express": "^11.0.1",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"serialport": "^10.5.0",
|
||||
"@serialport/parser-readline": "^2.0.0",
|
||||
"rxjs": "^7.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3.2.0",
|
||||
"@eslint/js": "^9.18.0",
|
||||
"@nestjs/cli": "^11.0.0",
|
||||
"@nestjs/schematics": "^11.0.0",
|
||||
"@nestjs/testing": "^11.0.1",
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/node": "^22.10.7",
|
||||
"@types/supertest": "^6.0.2",
|
||||
"eslint": "^9.18.0",
|
||||
"eslint-config-prettier": "^10.0.1",
|
||||
"eslint-plugin-prettier": "^5.2.2",
|
||||
"globals": "^16.0.0",
|
||||
"jest": "^30.0.0",
|
||||
"prettier": "^3.4.2",
|
||||
"source-map-support": "^0.5.21",
|
||||
"supertest": "^7.0.0",
|
||||
"ts-jest": "^29.2.5",
|
||||
"ts-loader": "^9.5.2",
|
||||
"ts-node": "^10.9.2",
|
||||
"tsconfig-paths": "^4.2.0",
|
||||
"typescript": "^5.7.3",
|
||||
"typescript-eslint": "^8.20.0"
|
||||
},
|
||||
"jest": {
|
||||
"moduleFileExtensions": [
|
||||
"js",
|
||||
"json",
|
||||
"ts"
|
||||
],
|
||||
"rootDir": "src",
|
||||
"testRegex": ".*\\.spec\\.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
},
|
||||
"collectCoverageFrom": [
|
||||
"**/*.(t|j)s"
|
||||
],
|
||||
"coverageDirectory": "../coverage",
|
||||
"testEnvironment": "node"
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
describe('AppController', () => {
|
||||
let appController: AppController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const app: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
}).compile();
|
||||
|
||||
appController = app.get<AppController>(AppController);
|
||||
});
|
||||
|
||||
describe('root', () => {
|
||||
it('should return "Hello World!"', () => {
|
||||
expect(appController.getHello()).toBe('Hello World!');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(private readonly appService: AppService) {}
|
||||
|
||||
@Get()
|
||||
getHello(): string {
|
||||
return this.appService.getHello();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { SerialModule } from './serial/serial.module';
|
||||
|
||||
@Module({
|
||||
imports: [SerialModule],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
})
|
||||
export class AppModule {}
|
||||
@@ -1,8 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
import { NestExpressApplication } from '@nestjs/platform-express';
|
||||
import { join } from 'path';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
|
||||
bufferLogs: true,
|
||||
});
|
||||
|
||||
// Serve static frontend (built assets copied to /app/public in container)
|
||||
const publicDir = join(process.cwd(), 'public');
|
||||
app.useStaticAssets(publicDir);
|
||||
|
||||
// Basic health endpoint
|
||||
app.getHttpAdapter().get('/healthz', (_req: any, res: any) => {
|
||||
res.json({ ok: true, ts: Date.now() });
|
||||
});
|
||||
|
||||
const port = Number(process.env.PORT || 3000);
|
||||
await app.listen(port);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`[bootstrap] Listening on :${port}`);
|
||||
}
|
||||
bootstrap().catch((e) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('Fatal bootstrap error', e);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -1,89 +0,0 @@
|
||||
import { Controller, Get, Post, Body, Res, Req } from '@nestjs/common';
|
||||
import type { Response, Request } from 'express';
|
||||
import { SerialService } from './serial.service';
|
||||
|
||||
@Controller('serial')
|
||||
export class SerialController {
|
||||
constructor(private readonly serial: SerialService) {}
|
||||
|
||||
@Get('ports')
|
||||
async ports() {
|
||||
console.log('[SerialController] GET /serial/ports');
|
||||
const p = await this.serial.listPorts();
|
||||
console.log('[SerialController] ports ->', p);
|
||||
return p;
|
||||
}
|
||||
|
||||
@Post('open')
|
||||
async open(@Body() body: { path: string; baud?: number }) {
|
||||
console.log('[SerialController] POST /serial/open', body);
|
||||
try {
|
||||
this.serial.open(body.path, body.baud ?? 115200);
|
||||
return { ok: true };
|
||||
} catch (e: any) {
|
||||
console.error('[SerialController] open error', e);
|
||||
return { ok: false, error: String(e) };
|
||||
}
|
||||
}
|
||||
|
||||
@Post('close')
|
||||
async close() {
|
||||
console.log('[SerialController] POST /serial/close');
|
||||
this.serial.close();
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
@Post('send')
|
||||
async send(@Body() body: { payload: string }) {
|
||||
console.log('[SerialController] POST /serial/send', body.payload);
|
||||
try {
|
||||
this.serial.send(body.payload);
|
||||
return { ok: true };
|
||||
} catch (e: any) {
|
||||
console.error('[SerialController] send error', e);
|
||||
return { ok: false, error: String(e) };
|
||||
}
|
||||
}
|
||||
|
||||
@Get('status')
|
||||
status() {
|
||||
return this.serial.status();
|
||||
}
|
||||
|
||||
@Get('stream')
|
||||
stream(@Req() req: Request, @Res() res: Response) {
|
||||
// SSE stream
|
||||
res.set({
|
||||
'Content-Type': 'text/event-stream',
|
||||
'Cache-Control': 'no-cache',
|
||||
Connection: 'keep-alive',
|
||||
});
|
||||
res.flushHeaders?.();
|
||||
|
||||
const sendEvent = (event: string, data: any) => {
|
||||
res.write(`event: ${event}\n`);
|
||||
res.write(`data: ${JSON.stringify(data)}\n\n`);
|
||||
};
|
||||
|
||||
const offData = this.serial.on('data', (line) => sendEvent('data', line));
|
||||
const offOpen = this.serial.on('open', () => sendEvent('open', ''));
|
||||
const offClose = this.serial.on('close', () => sendEvent('close', ''));
|
||||
const offErr = this.serial.on('error', (err) => sendEvent('error', String(err)));
|
||||
|
||||
console.log('[SerialController] SSE client connected');
|
||||
|
||||
// send a ping every 20s to keep connection alive
|
||||
const ping = setInterval(() => res.write(': ping\n\n'), 20000);
|
||||
|
||||
req.on('close', () => {
|
||||
console.log('[SerialController] SSE client disconnected');
|
||||
clearInterval(ping);
|
||||
offData();
|
||||
offOpen();
|
||||
offClose();
|
||||
offErr();
|
||||
});
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { SerialService } from './serial.service';
|
||||
import { SerialController } from './serial.controller';
|
||||
|
||||
@Module({
|
||||
providers: [SerialService],
|
||||
controllers: [SerialController],
|
||||
exports: [SerialService],
|
||||
})
|
||||
export class SerialModule {}
|
||||
@@ -1,206 +0,0 @@
|
||||
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
||||
import { EventEmitter } from 'events';
|
||||
// serialport has ESM/CJS shape differences and limited typings; require at runtime and keep as any
|
||||
const SP: any = require('serialport');
|
||||
const ReadlineParserModule: any = require('@serialport/parser-readline');
|
||||
// normalize constructor and parser
|
||||
const SerialCtor: any = SP?.SerialPort ?? SP;
|
||||
const ParserCtor: any = ReadlineParserModule?.ReadlineParser ?? ReadlineParserModule;
|
||||
|
||||
type PortInfo = {
|
||||
path: string;
|
||||
manufacturer?: string;
|
||||
serialNumber?: string;
|
||||
pnpId?: string;
|
||||
locationId?: string;
|
||||
productId?: string;
|
||||
vendorId?: string;
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class SerialService implements OnModuleDestroy, OnModuleInit {
|
||||
private emitter = new EventEmitter();
|
||||
private port: any = null;
|
||||
private parser: any = null;
|
||||
private verbose = true; // internal debug; does not change emitted payload format
|
||||
|
||||
constructor() {
|
||||
// Wrap emitter.emit to log every emitted event centrally
|
||||
const origEmit = this.emitter.emit.bind(this.emitter);
|
||||
this.emitter.emit = (event: string, ...args: any[]) => {
|
||||
if (this.verbose) {
|
||||
try {
|
||||
const printable = args.map(a => typeof a === 'object' ? JSON.stringify(a) : String(a));
|
||||
console.log('[SerialService][EVENT]', event, printable.join(' '));
|
||||
} catch {
|
||||
console.log('[SerialService][EVENT]', event, args.length, 'arg(s)');
|
||||
}
|
||||
}
|
||||
return origEmit(event, ...args);
|
||||
};
|
||||
}
|
||||
|
||||
async listPorts(): Promise<PortInfo[]> {
|
||||
console.log('[SerialService] listPorts()');
|
||||
let ports: any[] = [];
|
||||
try {
|
||||
if (typeof SP.list === 'function') {
|
||||
ports = await SP.list();
|
||||
} else {
|
||||
// try the separate list package
|
||||
try {
|
||||
const listMod: any = require('@serialport/list');
|
||||
if (typeof listMod.list === 'function') ports = await listMod.list();
|
||||
else if (typeof listMod === 'function') ports = await listMod();
|
||||
} catch (e) {
|
||||
// fallback: empty list
|
||||
ports = [];
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[SerialService] listPorts error', e);
|
||||
ports = [];
|
||||
}
|
||||
console.log('[SerialService] listPorts ->', ports);
|
||||
return ports.map((p: any) => ({
|
||||
path: p.path || p.comName,
|
||||
manufacturer: p.manufacturer,
|
||||
serialNumber: p.serialNumber,
|
||||
pnpId: p.pnpId,
|
||||
locationId: p.locationId,
|
||||
productId: p.productId,
|
||||
vendorId: p.vendorId,
|
||||
}));
|
||||
}
|
||||
|
||||
open(path: string, baudRate = 115200) {
|
||||
this.close();
|
||||
console.log('[SerialService] opening port', path, 'baud', baudRate);
|
||||
this.port = new SerialCtor({ path, baudRate, autoOpen: false } as any);
|
||||
this.parser = this.port.pipe(new ParserCtor({ delimiter: '\n' }));
|
||||
|
||||
this.port.on('open', () => {
|
||||
console.log('[SerialService] port open', path);
|
||||
this.emitter.emit('open');
|
||||
});
|
||||
this.port.on('error', (err: any) => {
|
||||
console.error('[SerialService] port error', err);
|
||||
this.emitter.emit('error', err?.message ?? String(err));
|
||||
});
|
||||
this.port.on('close', () => { this.emitter.emit('close'); });
|
||||
this.parser.on('data', (line: string) => {
|
||||
const clean = line.replace(/[\r\n]+$/, '');
|
||||
if (this.verbose) console.log('[SerialService] RX:', clean);
|
||||
this.emitter.emit('data', clean);
|
||||
});
|
||||
|
||||
// open the port
|
||||
try {
|
||||
this.port.open((err: any) => {
|
||||
if (err) {
|
||||
console.error('[SerialService] open callback error', err);
|
||||
this.emitter.emit('error', err?.message ?? String(err));
|
||||
} else {
|
||||
console.log('[SerialService] open callback success');
|
||||
}
|
||||
});
|
||||
} catch (e: any) {
|
||||
console.error('[SerialService] open exception', e);
|
||||
this.emitter.emit('error', e?.message ?? String(e));
|
||||
}
|
||||
}
|
||||
|
||||
close() {
|
||||
if (this.parser) {
|
||||
this.parser.removeAllListeners();
|
||||
this.parser = null;
|
||||
}
|
||||
if (this.port) {
|
||||
try {
|
||||
console.log('[SerialService] closing port', this.port?.path ?? '(unknown)');
|
||||
this.port.close();
|
||||
} catch (e) {
|
||||
console.error('[SerialService] close error', e);
|
||||
}
|
||||
this.port = null;
|
||||
}
|
||||
this.emitter.emit('close');
|
||||
}
|
||||
|
||||
send(line: string) {
|
||||
if (!this.port || !(this.port.writable || this.port.isOpen)) {
|
||||
console.warn('[SerialService] send called but port not open');
|
||||
throw new Error('Port not open');
|
||||
}
|
||||
// write and flush
|
||||
console.log('[SerialService] TX:', line);
|
||||
this.port.write(line + '\n', (err: any) => {
|
||||
if (err) console.error('[SerialService] write error', err);
|
||||
else console.log('[SerialService] write success');
|
||||
});
|
||||
}
|
||||
|
||||
status() {
|
||||
const s = {
|
||||
open: !!(this.port && (this.port.isOpen || this.port.writable)),
|
||||
path: this.port?.path ?? null,
|
||||
};
|
||||
console.log('[SerialService] status ->', s);
|
||||
return s;
|
||||
}
|
||||
|
||||
on(event: 'data' | 'open' | 'close' | 'error', cb: (...args: any[]) => void) {
|
||||
this.emitter.on(event, cb);
|
||||
return () => this.emitter.off(event, cb);
|
||||
}
|
||||
// Allow subscription to extended events (disconnect, drain, etc.)
|
||||
onAny(event: string, cb: (...args: any[]) => void) {
|
||||
this.emitter.on(event, cb);
|
||||
return () => this.emitter.off(event, cb);
|
||||
}
|
||||
|
||||
onModuleDestroy() {
|
||||
this.close();
|
||||
}
|
||||
|
||||
async onModuleInit() {
|
||||
// Priority: explicit env vars > auto-detect
|
||||
const explicit = process.env.SERIAL_PORT || process.env.PICO_SERIAL_PORT;
|
||||
const baud = Number(process.env.SERIAL_BAUD || process.env.PICO_BAUD || 115200);
|
||||
if (explicit) {
|
||||
try {
|
||||
console.log('[SerialService] AUTO opening explicit port', explicit, 'baud=', baud);
|
||||
this.open(explicit, baud);
|
||||
return;
|
||||
} catch (e: any) {
|
||||
console.warn('[SerialService] explicit open failed', e?.message ?? e);
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt auto-detect of Pico (USB first, then common UART paths)
|
||||
try {
|
||||
const ports = await this.listPorts();
|
||||
// Prefer vendorId 2e8a (Pico)
|
||||
let candidate = ports.find(p => (p.vendorId || '').toLowerCase() === '2e8a');
|
||||
if (!candidate) {
|
||||
const common = ['/dev/serial0', '/dev/ttyACM0', '/dev/ttyAMA0'];
|
||||
candidate = ports.find(p => p.path && common.includes(p.path));
|
||||
}
|
||||
// Windows fallback: highest numbered COM port
|
||||
if (!candidate) {
|
||||
const winCom = ports
|
||||
.filter(p => /^COM\d+$/i.test(p.path))
|
||||
.sort((a, b) => Number(b.path.replace(/\D/g, '')) - Number(a.path.replace(/\D/g, '')))[0];
|
||||
if (winCom) candidate = winCom;
|
||||
}
|
||||
if (candidate && candidate.path) {
|
||||
console.log('[SerialService] AUTO opening detected port', candidate.path);
|
||||
this.open(candidate.path, baud);
|
||||
} else {
|
||||
console.log('[SerialService] No serial port auto-detected (will remain idle)');
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.warn('[SerialService] auto-detect failed', e?.message ?? e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import * as request from 'supertest';
|
||||
import { App } from 'supertest/types';
|
||||
import { AppModule } from './../src/app.module';
|
||||
|
||||
describe('AppController (e2e)', () => {
|
||||
let app: INestApplication<App>;
|
||||
|
||||
beforeEach(async () => {
|
||||
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
}).compile();
|
||||
|
||||
app = moduleFixture.createNestApplication();
|
||||
await app.init();
|
||||
});
|
||||
|
||||
it('/ (GET)', () => {
|
||||
return request(app.getHttpServer())
|
||||
.get('/')
|
||||
.expect(200)
|
||||
.expect('Hello World!');
|
||||
});
|
||||
});
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"moduleFileExtensions": ["js", "json", "ts"],
|
||||
"rootDir": ".",
|
||||
"testEnvironment": "node",
|
||||
"testRegex": ".e2e-spec.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "nodenext",
|
||||
"moduleResolution": "nodenext",
|
||||
"resolvePackageJsonExports": true,
|
||||
"esModuleInterop": true,
|
||||
"isolatedModules": true,
|
||||
"declaration": true,
|
||||
"removeComments": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "ES2023",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./",
|
||||
"incremental": true,
|
||||
"skipLibCheck": true,
|
||||
"strictNullChecks": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noImplicitAny": true,
|
||||
"strictBindCallApply": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
node_modules
|
||||
.svelte-kit
|
||||
dist
|
||||
build
|
||||
coverage
|
||||
npm-debug.log
|
||||
.DS_Store
|
||||
.git
|
||||
/.gitignore
|
||||
*.log
|
||||
24
frontend/.gitignore
vendored
24
frontend/.gitignore
vendored
@@ -1,24 +0,0 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
3
frontend/.vscode/extensions.json
vendored
3
frontend/.vscode/extensions.json
vendored
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"recommendations": ["svelte.svelte-vscode"]
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
######## Combined Frontend + Backend build (single Node runtime) ########
|
||||
# This Dockerfile now builds BOTH the Svelte frontend and the NestJS backend
|
||||
# and serves the compiled frontend through the backend (Express static).
|
||||
|
||||
########################
|
||||
# 1) Frontend build #
|
||||
########################
|
||||
FROM node:20-bookworm-slim AS frontend-build
|
||||
WORKDIR /frontend
|
||||
COPY frontend/package*.json ./
|
||||
RUN npm install --no-audit --no-fund
|
||||
COPY frontend/ .
|
||||
RUN npm run build
|
||||
|
||||
########################
|
||||
# 2) Backend build #
|
||||
########################
|
||||
FROM node:20-bookworm-slim AS backend-build
|
||||
WORKDIR /app
|
||||
COPY backend/package*.json ./
|
||||
RUN npm install --no-audit --no-fund
|
||||
COPY backend/ .
|
||||
# Copy compiled frontend into backend/public (served statically by Nest)
|
||||
COPY --from=frontend-build /frontend/dist ./public
|
||||
RUN npm run build
|
||||
|
||||
########################
|
||||
# 3) Production image #
|
||||
########################
|
||||
FROM node:20-bookworm-slim AS runner
|
||||
ENV NODE_ENV=production
|
||||
WORKDIR /app
|
||||
|
||||
# Install only production deps (reuse original package.json)
|
||||
COPY backend/package*.json ./
|
||||
RUN npm install --omit=dev --no-audit --no-fund
|
||||
|
||||
# Copy backend dist + public assets
|
||||
COPY --from=backend-build /app/dist ./dist
|
||||
COPY --from=backend-build /app/public ./public
|
||||
|
||||
# Environment (override at runtime as needed)
|
||||
ENV PORT=3000 \
|
||||
SERIAL_BAUD=115200
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["node", "dist/main.js"]
|
||||
@@ -1,47 +0,0 @@
|
||||
# Svelte + TS + Vite
|
||||
|
||||
This template should help get you started developing with Svelte and TypeScript in Vite.
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode).
|
||||
|
||||
## Need an official Svelte framework?
|
||||
|
||||
Check out [SvelteKit](https://github.com/sveltejs/kit#readme), which is also powered by Vite. Deploy anywhere with its serverless-first approach and adapt to various platforms, with out of the box support for TypeScript, SCSS, and Less, and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more.
|
||||
|
||||
## Technical considerations
|
||||
|
||||
**Why use this over SvelteKit?**
|
||||
|
||||
- It brings its own routing solution which might not be preferable for some users.
|
||||
- It is first and foremost a framework that just happens to use Vite under the hood, not a Vite app.
|
||||
|
||||
This template contains as little as possible to get started with Vite + TypeScript + Svelte, while taking into account the developer experience with regards to HMR and intellisense. It demonstrates capabilities on par with the other `create-vite` templates and is a good starting point for beginners dipping their toes into a Vite + Svelte project.
|
||||
|
||||
Should you later need the extended capabilities and extensibility provided by SvelteKit, the template has been structured similarly to SvelteKit so that it is easy to migrate.
|
||||
|
||||
**Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?**
|
||||
|
||||
Setting `compilerOptions.types` shuts out all other types not explicitly listed in the configuration. Using triple-slash references keeps the default TypeScript setting of accepting type information from the entire workspace, while also adding `svelte` and `vite/client` type information.
|
||||
|
||||
**Why include `.vscode/extensions.json`?**
|
||||
|
||||
Other templates indirectly recommend extensions via the README, but this file allows VS Code to prompt the user to install the recommended extension upon opening the project.
|
||||
|
||||
**Why enable `allowJs` in the TS template?**
|
||||
|
||||
While `allowJs: false` would indeed prevent the use of `.js` files in the project, it does not prevent the use of JavaScript syntax in `.svelte` files. In addition, it would force `checkJs: false`, bringing the worst of both worlds: not being able to guarantee the entire codebase is TypeScript, and also having worse typechecking for the existing JavaScript. In addition, there are valid use cases in which a mixed codebase may be relevant.
|
||||
|
||||
**Why is HMR not preserving my local component state?**
|
||||
|
||||
HMR state preservation comes with a number of gotchas! It has been disabled by default in both `svelte-hmr` and `@sveltejs/vite-plugin-svelte` due to its often surprising behavior. You can read the details [here](https://github.com/rixo/svelte-hmr#svelte-hmr).
|
||||
|
||||
If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR.
|
||||
|
||||
```ts
|
||||
// store.ts
|
||||
// An extremely simple external store
|
||||
import { writable } from 'svelte/store'
|
||||
export default writable(0)
|
||||
```
|
||||
@@ -1,19 +0,0 @@
|
||||
services:
|
||||
app:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: Dockerfile
|
||||
container_name: schafkop-app
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- PORT=3000
|
||||
# Optionally set SERIAL_PORT or PICO_SERIAL_PORT for auto-open
|
||||
# - SERIAL_PORT=/dev/serial0
|
||||
# - SERIAL_BAUD=115200
|
||||
ports:
|
||||
- "80:3000"
|
||||
# Uncomment and adjust one of the following for hardware access on a Pi:
|
||||
# devices:
|
||||
# - /dev/serial0:/dev/serial0
|
||||
# - /dev/ttyACM0:/dev/ttyACM0
|
||||
@@ -1,13 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Schafkopf Bot — Play & Train</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
1986
frontend/package-lock.json
generated
1986
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,24 +0,0 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"check": "svelte-check --tsconfig ./tsconfig.app.json && tsc -p tsconfig.node.json"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/vite-plugin-svelte": "^6.1.1",
|
||||
"@tsconfig/svelte": "^5.0.4",
|
||||
"svelte": "^5.38.1",
|
||||
"svelte-check": "^4.3.1",
|
||||
"tailwindcss": "^4.1.12",
|
||||
"typescript": "~5.8.3",
|
||||
"vite": "^7.1.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tailwindcss/vite": "^4.1.12"
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||
|
Before Width: | Height: | Size: 1.5 KiB |
@@ -1,229 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import { writable } from 'svelte/store';
|
||||
import SendBox from './SendBox.svelte';
|
||||
|
||||
const ports = writable<Array<any>>([]);
|
||||
const log = writable<string[]>([]);
|
||||
const connected = writable(false);
|
||||
const portOpen = writable(false);
|
||||
let es: EventSource | null = null;
|
||||
|
||||
function addLog(line: string) {
|
||||
// keep a fairly large history and prefix with an ISO timestamp
|
||||
log.update((l) => [new Date().toISOString() + ' ' + line, ...l].slice(0, 2000));
|
||||
}
|
||||
|
||||
async function list() {
|
||||
console.log('[serial] list() called');
|
||||
const res = await fetch('/serial/ports');
|
||||
const data = await res.json();
|
||||
console.log('[serial] list() ->', data);
|
||||
ports.set(data);
|
||||
}
|
||||
|
||||
async function openPort(path: string) {
|
||||
console.log('[serial] openPort()', path);
|
||||
const res = await fetch('/serial/open', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ path }) });
|
||||
const j = await res.json().catch(() => null);
|
||||
console.log('[serial] openPort result', j);
|
||||
// log result and refresh status
|
||||
if (j?.ok) addLog('PORT: open requested ' + path);
|
||||
else addLog('PORT: open request failed - ' + (j?.error ?? 'unknown'));
|
||||
setTimeout(getStatus, 300);
|
||||
}
|
||||
|
||||
async function closePort() {
|
||||
console.log('[serial] closePort()');
|
||||
const res = await fetch('/serial/close', { method: 'POST' });
|
||||
const j = await res.json().catch(() => null);
|
||||
console.log('[serial] closePort result', j);
|
||||
addLog('PORT: close requested');
|
||||
}
|
||||
|
||||
async function sendLine(txt: string) {
|
||||
console.log('[serial] sendLine()', txt);
|
||||
const res = await fetch('/serial/send', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ payload: txt }) });
|
||||
const j = await res.json().catch(() => null);
|
||||
console.log('[serial] sendLine result', j);
|
||||
if (!j?.ok) addLog('TX error: ' + (j?.error ?? 'unknown'));
|
||||
}
|
||||
|
||||
async function getStatus() {
|
||||
console.log('[serial] getStatus()');
|
||||
try {
|
||||
const res = await fetch('/serial/status');
|
||||
const j = await res.json();
|
||||
console.log('[serial] getStatus ->', j);
|
||||
portOpen.set(!!j.open);
|
||||
} catch (e) {
|
||||
console.warn('[serial] getStatus failed', e);
|
||||
portOpen.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
function startStream() {
|
||||
if (es) return;
|
||||
console.log('[serial] startStream()');
|
||||
es = new EventSource('/serial/stream');
|
||||
// connection lifecycle events - also log them so the serial box shows open/close/errors
|
||||
es.addEventListener('open', () => { console.log('[serial][SSE] open'); connected.set(true); addLog('[SSE] connected'); });
|
||||
es.addEventListener('close', () => { console.log('[serial][SSE] close'); connected.set(false); addLog('[SSE] disconnected'); });
|
||||
es.addEventListener('error', (e: any) => { console.warn('[serial][SSE] error', e); addLog('[SSE] error: ' + (e?.message ?? JSON.stringify(e))); });
|
||||
|
||||
// data events contain the actual lines emitted by the Pico; parse JSON payloads but fall back to raw
|
||||
es.addEventListener('data', (ev: any) => {
|
||||
console.log('[serial][SSE] data event', ev.data);
|
||||
const raw = ev.data as string;
|
||||
let line: string | undefined;
|
||||
try {
|
||||
const parsed = JSON.parse(raw);
|
||||
if (parsed && typeof parsed === 'object' && 'line' in parsed) {
|
||||
line = (parsed as any).line;
|
||||
} else if (typeof parsed === 'string') {
|
||||
line = parsed; // backend sent a plain JSON string
|
||||
}
|
||||
} catch {
|
||||
// not JSON -> treat as plain text
|
||||
}
|
||||
if (!line) line = raw;
|
||||
addLog('RX: ' + line);
|
||||
});
|
||||
}
|
||||
|
||||
function stopStream() {
|
||||
console.log('[serial] stopStream()');
|
||||
es?.close();
|
||||
es = null;
|
||||
connected.set(false);
|
||||
}
|
||||
|
||||
let statusInterval: any;
|
||||
// quick test command defaults
|
||||
let stepVal: string = '4096';
|
||||
let dirVal: string = '1';
|
||||
let speedVal: string = '3000';
|
||||
onMount(() => {
|
||||
list();
|
||||
startStream();
|
||||
statusInterval = setInterval(getStatus, 1000);
|
||||
getStatus();
|
||||
});
|
||||
onDestroy(() => {
|
||||
stopStream();
|
||||
clearInterval(statusInterval);
|
||||
});
|
||||
|
||||
function sendStepCmd() {
|
||||
const steps = Number(stepVal);
|
||||
const dir = Number(dirVal) === 1 ? 1 : 0;
|
||||
if (!Number.isFinite(steps) || steps <= 0) {
|
||||
addLog('TX error: invalid STEP value: ' + stepVal);
|
||||
return;
|
||||
}
|
||||
const line = `STEP ${steps} ${dir}`;
|
||||
sendLine(line);
|
||||
addLog('TX: ' + line);
|
||||
}
|
||||
|
||||
function sendSpeedCmd() {
|
||||
const d = Number(speedVal);
|
||||
if (!Number.isFinite(d) || d <= 0) {
|
||||
addLog('TX error: invalid SPEED value: ' + speedVal);
|
||||
return;
|
||||
}
|
||||
const line = `SPEED ${d}`;
|
||||
sendLine(line);
|
||||
addLog('TX: ' + line);
|
||||
}
|
||||
</script>
|
||||
|
||||
<main class="min-h-screen bg-gradient-to-b from-bg to-surface text-gray-100 p-8">
|
||||
<h1 class="text-3xl font-bold underline">
|
||||
Hello world!
|
||||
</h1>
|
||||
<div class="container mx-auto">
|
||||
<header class="flex items-center justify-between mb-6">
|
||||
<div>
|
||||
<h1 class="text-2xl font-semibold">Raspberry Pico</h1>
|
||||
<p class="text-sm text-gray-400">Serial monitor & command tester</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
<span class="text-sm text-gray-300">SSE: {$connected ? 'connected' : 'disconnected'}</span>
|
||||
<button class="px-3 py-1 bg-primary text-white rounded-md text-sm" on:click={startStream}>Start</button>
|
||||
<button class="px-3 py-1 bg-gray-700 text-white rounded-md text-sm" on:click={stopStream}>Stop</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="grid grid-cols-12 gap-6">
|
||||
<aside class="col-span-4 bg-gray-900/60 p-4 rounded-lg border border-gray-800">
|
||||
<section class="mb-4">
|
||||
<h3 class="text-sm text-gray-300 font-medium">Available ports</h3>
|
||||
<div class="flex items-center gap-2 mt-2">
|
||||
<button class="px-2 py-1 text-sm bg-gray-700 rounded" on:click={list}>Refresh</button>
|
||||
<button class="px-2 py-1 text-sm bg-red-600 rounded" on:click={closePort}>Close port</button>
|
||||
</div>
|
||||
<ul class="mt-3 space-y-2">
|
||||
{#each $ports as p}
|
||||
<li class="flex items-center justify-between bg-gray-800/40 p-2 rounded">
|
||||
<code class="text-xs text-gray-200">{p.path}</code>
|
||||
<button class="px-2 py-1 text-sm bg-primary rounded" on:click={() => openPort(p.path)}>Open</button>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section class="mb-4">
|
||||
<h3 class="text-sm text-gray-300 font-medium">Send</h3>
|
||||
<div class="mt-2 flex items-center gap-2">
|
||||
<div class="text-xs text-gray-300">Port: <span class="font-medium">{$portOpen ? 'open' : 'closed'}</span></div>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<SendBox disabled={!$portOpen} on:send={(e) => { sendLine(e.detail); addLog('TX: ' + e.detail); }} />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h3 class="text-sm text-gray-300 font-medium">Quick commands</h3>
|
||||
<div class="mt-2 space-y-2">
|
||||
<div class="flex gap-2 items-center">
|
||||
<input class="w-28 p-2 rounded bg-gray-800 text-sm" type="number" bind:value={stepVal} min="1" />
|
||||
<select class="p-2 rounded bg-gray-800 text-sm" bind:value={dirVal}>
|
||||
<option value="1">1 (forward)</option>
|
||||
<option value="0">0 (reverse)</option>
|
||||
</select>
|
||||
<button class="px-3 py-1 bg-primary text-white rounded" on:click={sendStepCmd} disabled={!$portOpen}>Send STEP</button>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-2 items-center">
|
||||
<input class="w-28 p-2 rounded bg-gray-800 text-sm" type="number" bind:value={speedVal} min="1" />
|
||||
<button class="px-3 py-1 bg-primary text-white rounded" on:click={sendSpeedCmd} disabled={!$portOpen}>Send SPEED</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</aside>
|
||||
|
||||
<section class="col-span-8 bg-gray-900/60 p-4 rounded-lg border border-gray-800 flex flex-col">
|
||||
<div class="flex items-center justify-between mb-3">
|
||||
<h3 class="text-sm text-gray-300 font-medium">Live log</h3>
|
||||
<div class="text-xs text-gray-400">Showing last {2000} lines</div>
|
||||
</div>
|
||||
<div class="flex-1 overflow-auto bg-[#0b0b0b] p-3 rounded text-sm font-mono text-gray-100">
|
||||
{#each $log as l}
|
||||
<div class="py-0.5"><code class="text-xs">{l}</code></div>
|
||||
{/each}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
main { padding: 1rem; font-family: system-ui, -apple-system, 'Segoe UI', Roboto; color:#111 }
|
||||
h1 { margin-bottom:0.5rem }
|
||||
section { margin-top:1rem; }
|
||||
button { margin-left:0.5rem }
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
export let placeholder = 'Type a line to send';
|
||||
export let disabled: boolean = false;
|
||||
const dispatch = createEventDispatcher();
|
||||
let txt = '';
|
||||
function doSend() {
|
||||
if (!txt) return;
|
||||
console.log('[SendBox] dispatch send', txt);
|
||||
dispatch('send', txt);
|
||||
txt = '';
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="mt-2 flex gap-2 items-center">
|
||||
<input class="flex-1 p-2 rounded bg-gray-800 text-sm text-gray-100" bind:value={txt} placeholder={placeholder} on:keydown={(e) => e.key === 'Enter' && doSend()} disabled={disabled} />
|
||||
<button class="px-3 py-1 bg-primary text-white rounded text-sm" on:click={doSend} disabled={disabled}>Send</button>
|
||||
</div>
|
||||
@@ -1,44 +0,0 @@
|
||||
:root {
|
||||
--font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
--bg: #0b0b0b;
|
||||
--surface: #121212;
|
||||
--text: #eaeaea;
|
||||
--muted: #9aa3b2;
|
||||
--accent: #7c6cff;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
html, body { height: 100%; }
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: var(--font-family);
|
||||
color: var(--text);
|
||||
background: linear-gradient(180deg, var(--bg), var(--surface));
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
a { color: var(--accent); text-decoration: none; }
|
||||
a:hover { opacity: 0.9; }
|
||||
|
||||
/* utility container used by App.svelte */
|
||||
.container { max-width: 1100px; margin: 0 auto; padding: 1.25rem; }
|
||||
|
||||
/* accessible focus styles */
|
||||
:focus { outline: 3px solid rgba(124,108,255,0.18); outline-offset: 2px; }
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root { --bg: #fafafa; --surface:#fff; --text:#111827; --muted:#556; }
|
||||
}
|
||||
|
||||
|
||||
/* small helpers that complement tailwind tokens */
|
||||
.container { max-width: 1100px; margin: 0 auto; padding: 1.25rem; }
|
||||
|
||||
:focus { outline: 3px solid rgba(124,108,255,0.18); outline-offset: 2px; }
|
||||
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
@import "tailwindcss";
|
||||
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="26.6" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 308"><path fill="#FF3E00" d="M239.682 40.707C211.113-.182 154.69-12.301 113.895 13.69L42.247 59.356a82.198 82.198 0 0 0-37.135 55.056a86.566 86.566 0 0 0 8.536 55.576a82.425 82.425 0 0 0-12.296 30.719a87.596 87.596 0 0 0 14.964 66.244c28.574 40.893 84.997 53.007 125.787 27.016l71.648-45.664a82.182 82.182 0 0 0 37.135-55.057a86.601 86.601 0 0 0-8.53-55.577a82.409 82.409 0 0 0 12.29-30.718a87.573 87.573 0 0 0-14.963-66.244"></path><path fill="#FFF" d="M106.889 270.841c-23.102 6.007-47.497-3.036-61.103-22.648a52.685 52.685 0 0 1-9.003-39.85a49.978 49.978 0 0 1 1.713-6.693l1.35-4.115l3.671 2.697a92.447 92.447 0 0 0 28.036 14.007l2.663.808l-.245 2.659a16.067 16.067 0 0 0 2.89 10.656a17.143 17.143 0 0 0 18.397 6.828a15.786 15.786 0 0 0 4.403-1.935l71.67-45.672a14.922 14.922 0 0 0 6.734-9.977a15.923 15.923 0 0 0-2.713-12.011a17.156 17.156 0 0 0-18.404-6.832a15.78 15.78 0 0 0-4.396 1.933l-27.35 17.434a52.298 52.298 0 0 1-14.553 6.391c-23.101 6.007-47.497-3.036-61.101-22.649a52.681 52.681 0 0 1-9.004-39.849a49.428 49.428 0 0 1 22.34-33.114l71.664-45.677a52.218 52.218 0 0 1 14.563-6.398c23.101-6.007 47.497 3.036 61.101 22.648a52.685 52.685 0 0 1 9.004 39.85a50.559 50.559 0 0 1-1.713 6.692l-1.35 4.116l-3.67-2.693a92.373 92.373 0 0 0-28.037-14.013l-2.664-.809l.246-2.658a16.099 16.099 0 0 0-2.89-10.656a17.143 17.143 0 0 0-18.398-6.828a15.786 15.786 0 0 0-4.402 1.935l-71.67 45.674a14.898 14.898 0 0 0-6.73 9.975a15.9 15.9 0 0 0 2.709 12.012a17.156 17.156 0 0 0 18.404 6.832a15.841 15.841 0 0 0 4.402-1.935l27.345-17.427a52.147 52.147 0 0 1 14.552-6.397c23.101-6.006 47.497 3.037 61.102 22.65a52.681 52.681 0 0 1 9.003 39.848a49.453 49.453 0 0 1-22.34 33.12l-71.664 45.673a52.218 52.218 0 0 1-14.563 6.398"></path></svg>
|
||||
|
Before Width: | Height: | Size: 1.9 KiB |
@@ -1,96 +0,0 @@
|
||||
<script lang="ts">
|
||||
// Simple game starter UI that posts a start command to the backend.
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
type Seat = 'North' | 'East' | 'South' | 'West';
|
||||
|
||||
let robotSeat: Seat = 'South';
|
||||
let difficulty: 'easy' | 'medium' | 'hard' = 'medium';
|
||||
let includeRobot = true;
|
||||
let isStarting = false;
|
||||
const logs = writable<string[]>([]);
|
||||
|
||||
function appendLog(line: string) {
|
||||
logs.update((ls) => {
|
||||
ls.push(line);
|
||||
return ls.slice(-50);
|
||||
});
|
||||
}
|
||||
|
||||
async function startGame() {
|
||||
isStarting = true;
|
||||
appendLog(`Requesting new game (robotSeat=${robotSeat}, difficulty=${difficulty}, includeRobot=${includeRobot})`);
|
||||
|
||||
try {
|
||||
const resp = await fetch('/api/game/start', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ robotSeat, difficulty, includeRobot }),
|
||||
});
|
||||
|
||||
if (!resp.ok) {
|
||||
const text = await resp.text();
|
||||
throw new Error(text || resp.statusText);
|
||||
}
|
||||
|
||||
const data = await resp.json();
|
||||
appendLog('Game started: ' + JSON.stringify(data));
|
||||
} catch (err) {
|
||||
appendLog('Error starting game: ' + String(err));
|
||||
} finally {
|
||||
isStarting = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<section class="game-starter card">
|
||||
<h4>Start a new physical game</h4>
|
||||
<p class="muted">The robot will join as one of the four players and physically plays cards on the table.</p>
|
||||
|
||||
<div class="form-row">
|
||||
<label>Robot seat</label>
|
||||
<select bind:value={robotSeat} aria-label="Robot seat">
|
||||
<option value="North">North</option>
|
||||
<option value="East">East</option>
|
||||
<option value="South">South</option>
|
||||
<option value="West">West</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<label>Difficulty</label>
|
||||
<select bind:value={difficulty} aria-label="Difficulty">
|
||||
<option value="easy">Easy</option>
|
||||
<option value="medium">Medium</option>
|
||||
<option value="hard">Hard</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-row-inline">
|
||||
<label><input type="checkbox" bind:checked={includeRobot} /> Include robot in this game</label>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<button class="btn primary" on:click={startGame} disabled={isStarting}> {isStarting ? 'Starting…' : 'Start game'} </button>
|
||||
</div>
|
||||
|
||||
<div class="log">
|
||||
<h5>Activity</h5>
|
||||
<ul>
|
||||
{#each $logs.slice().reverse() as line}
|
||||
<li>{line}</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<style>
|
||||
.game-starter { padding: 1rem; border-radius: 10px; }
|
||||
.muted { color: var(--muted); margin-top: 0.25rem; }
|
||||
.form-row { display:flex; flex-direction:column; gap:0.35rem; margin-top:0.8rem; }
|
||||
.form-row-inline { margin-top:0.8rem; }
|
||||
select { padding:0.5rem; border-radius:8px; background:transparent; color:inherit; border:1px solid rgba(255,255,255,0.04); }
|
||||
.actions { margin-top:1rem; }
|
||||
.log { margin-top:1rem; max-height:160px; overflow:auto; font-size:0.9rem; color:var(--muted); }
|
||||
.log ul { list-style:none; padding:0; margin:0; display:flex; flex-direction:column; gap:0.25rem; }
|
||||
</style>
|
||||
@@ -1,9 +0,0 @@
|
||||
import { mount } from 'svelte'
|
||||
import './app.css'
|
||||
import App from './App.svelte'
|
||||
|
||||
const app = mount(App, {
|
||||
target: document.getElementById('app')!,
|
||||
})
|
||||
|
||||
export default app
|
||||
2
frontend/src/vite-env.d.ts
vendored
2
frontend/src/vite-env.d.ts
vendored
@@ -1,2 +0,0 @@
|
||||
/// <reference types="svelte" />
|
||||
/// <reference types="vite/client" />
|
||||
@@ -1,8 +0,0 @@
|
||||
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
|
||||
|
||||
/** @type {import("@sveltejs/vite-plugin-svelte").SvelteConfig} */
|
||||
export default {
|
||||
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
|
||||
// for more information about preprocessors
|
||||
preprocess: vitePreprocess(),
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"extends": "@tsconfig/svelte/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"resolveJsonModule": true,
|
||||
/**
|
||||
* Typecheck JS in `.svelte` and `.js` files by default.
|
||||
* Disable checkJs if you'd like to use dynamic types in JS.
|
||||
* Note that setting allowJs false does not prevent the use
|
||||
* of JS in `.svelte` files.
|
||||
*/
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"isolatedModules": true,
|
||||
"moduleDetection": "force"
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte"]
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"target": "ES2023",
|
||||
"lib": ["ES2023"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
||||
import tailwindcss from '@tailwindcss/vite'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
svelte(),
|
||||
tailwindcss(),
|
||||
],
|
||||
server: {
|
||||
proxy: {
|
||||
// forward serial API calls (including SSE) to backend running on :3000
|
||||
'/serial': {
|
||||
target: 'http://localhost:3000',
|
||||
changeOrigin: true,
|
||||
ws: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
1
schafkopf-os/.gitignore
vendored
Normal file
1
schafkopf-os/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
target/
|
||||
7
schafkopf-os/Cargo.lock
generated
Normal file
7
schafkopf-os/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "schafkopf-os"
|
||||
version = "0.1.0"
|
||||
4
schafkopf-os/Cargo.toml
Normal file
4
schafkopf-os/Cargo.toml
Normal file
@@ -0,0 +1,4 @@
|
||||
[package]
|
||||
name = "schafkopf-os"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
27
schafkopf-os/README.md
Normal file
27
schafkopf-os/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# schafkopf-os — Test Frontend (Axum + Askama)
|
||||
|
||||
This crate serves a tiny test frontend using Axum + Askama and static assets.
|
||||
|
||||
## Run
|
||||
|
||||
```bash
|
||||
cargo run --manifest-path schafkopf-os/Cargo.toml
|
||||
```
|
||||
|
||||
Then open:
|
||||
|
||||
- http://127.0.0.1:3000 — server renders an Askama template
|
||||
- Click "Ping API" to call `GET /api/ping`
|
||||
|
||||
Or test the API directly:
|
||||
|
||||
```bash
|
||||
curl -s http://127.0.0.1:3000/api/ping | jq
|
||||
```
|
||||
|
||||
## Structure
|
||||
|
||||
- `src/main.rs` — Axum server with routes `/` and `/api/ping`, and static files at `/static`
|
||||
- `templates/index.html` — Askama template for the homepage
|
||||
- `static/styles.css` — Minimal styling
|
||||
- `static/app.js` — Browser script to call the ping API
|
||||
3
schafkopf-os/src/main.rs
Normal file
3
schafkopf-os/src/main.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
25
schafkopf-os/static/app.js
Normal file
25
schafkopf-os/static/app.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const btn = document.getElementById('pingBtn');
|
||||
const versionBtn = document.getElementById('versionBtn');
|
||||
const out = document.getElementById('result');
|
||||
|
||||
btn?.addEventListener('click', async () => {
|
||||
out.textContent = 'Requesting /api/ping…';
|
||||
try {
|
||||
const res = await fetch('/api/ping');
|
||||
const json = await res.json();
|
||||
out.textContent = JSON.stringify(json, null, 2);
|
||||
} catch (err) {
|
||||
out.textContent = 'Error: ' + (err?.message || String(err));
|
||||
}
|
||||
});
|
||||
|
||||
versionBtn?.addEventListener('click', async () => {
|
||||
out.textContent = 'Requesting /api/version…';
|
||||
try {
|
||||
const res = await fetch('/api/version');
|
||||
const json = await res.json();
|
||||
out.textContent = JSON.stringify(json, null, 2);
|
||||
} catch (err) {
|
||||
out.textContent = 'Error: ' + (err?.message || String(err));
|
||||
}
|
||||
});
|
||||
28
schafkopf-os/static/styles.css
Normal file
28
schafkopf-os/static/styles.css
Normal file
@@ -0,0 +1,28 @@
|
||||
/* Minimal styles for the test frontend */
|
||||
:root {
|
||||
color-scheme: light dark;
|
||||
--bg: #0e1217;
|
||||
--fg: #e9eef5;
|
||||
--muted: #94a3b8;
|
||||
--accent: #4f46e5;
|
||||
--card: #111827;
|
||||
--border: #1f2937;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
html, body { margin: 0; padding: 0; font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji"; }
|
||||
|
||||
body { background: var(--bg); color: var(--fg); }
|
||||
|
||||
.container { max-width: 800px; margin: 3rem auto; padding: 0 1rem; }
|
||||
|
||||
h1 { font-size: 1.8rem; margin: 0 0 1rem; }
|
||||
.lead { color: var(--muted); margin: 0 0 1rem; }
|
||||
.version { color: var(--muted); font-size: 0.9rem; margin: 0 0 1.5rem; }
|
||||
|
||||
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; }
|
||||
|
||||
button { background: var(--accent); color: white; border: none; padding: 0.6rem 1rem; border-radius: 8px; cursor: pointer; margin-right: 0.5rem; }
|
||||
button:hover { filter: brightness(1.1); }
|
||||
|
||||
pre { background: #0b0f14; border: 1px solid var(--border); padding: 0.75rem; border-radius: 8px; overflow: auto; }
|
||||
25
schafkopf-os/templates/index.html
Normal file
25
schafkopf-os/templates/index.html
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>{{ title }}</title>
|
||||
<link rel="stylesheet" href="/static/styles.css" />
|
||||
</head>
|
||||
<body>
|
||||
<main class="container">
|
||||
<h1>{{ title }}</h1>
|
||||
<p class="lead">{{ message }}</p>
|
||||
<p class="version">Version: {{ version }}</p>
|
||||
|
||||
<section class="card">
|
||||
<h2>API Test</h2>
|
||||
<button id="pingBtn">Ping API</button>
|
||||
<button id="versionBtn">Get Version</button>
|
||||
<pre id="result">Waiting…</pre>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<script src="/static/app.js" type="module"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user