robo backend
This commit is contained in:
parent
aab16a8b77
commit
77c3a1145e
3
src/robo-project/backend/.vscode/settings.json
vendored
Normal file
3
src/robo-project/backend/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"deno.enable": false
|
||||
}
|
||||
19
src/robo-project/backend/package.json
Normal file
19
src/robo-project/backend/package.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "@demofera/robo-backend",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.ts",
|
||||
"scripts": {
|
||||
"dev": "tsx watch src/index.ts"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "miqlangelo",
|
||||
"dependencies": {
|
||||
"@hono/node-server": "^1.14.0",
|
||||
"hono": "^4.7.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tsx": "^4.19.3",
|
||||
"typescript": "^5.8.2"
|
||||
}
|
||||
}
|
||||
68
src/robo-project/backend/src/index.ts
Normal file
68
src/robo-project/backend/src/index.ts
Normal file
@ -0,0 +1,68 @@
|
||||
import { serve } from '@hono/node-server';
|
||||
import { Hono } from 'hono';
|
||||
|
||||
const app = new Hono();
|
||||
|
||||
let statuslight = 'unknown';
|
||||
const hornMessages = [
|
||||
'möp möp',
|
||||
'honk honk!',
|
||||
'tuuut tuuut!',
|
||||
'🚗 möööööp!',
|
||||
'achtung, hupe aktiviert!',
|
||||
'🎺 ich bin ein Roboter, der hupen kann!',
|
||||
];
|
||||
|
||||
function getRandomHornMessage() {
|
||||
return hornMessages[Math.floor(Math.random() * hornMessages.length)];
|
||||
}
|
||||
|
||||
// GET
|
||||
app.get('/horn/beep', (c) =>
|
||||
c.json({ status: 200, message: getRandomHornMessage() })
|
||||
);
|
||||
app.get('/statuslight/on', (c) => {
|
||||
statuslight = 'on';
|
||||
return c.json({ status: 200, message: 'Statuslicht wurde eingeschaltet.' });
|
||||
});
|
||||
app.get('/statuslight/off', (c) => {
|
||||
statuslight = 'off';
|
||||
return c.json({ status: 200, message: 'Statuslicht wurde ausgeschaltet.' });
|
||||
});
|
||||
app.get('/statuslight/state', (c) => {
|
||||
return c.json({
|
||||
status: 200,
|
||||
state: statuslight,
|
||||
message: `Statuslicht ist aktuell: ${statuslight}`,
|
||||
});
|
||||
});
|
||||
|
||||
// POST
|
||||
app.post('/light', async (c) => {
|
||||
const body = await c.req.json();
|
||||
return c.json({
|
||||
status: 200,
|
||||
message: 'Lichter aktualisiert.',
|
||||
received: body,
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/move', async (c) => {
|
||||
const body = await c.req.json();
|
||||
const left = body.motorLeft?.direction || '?';
|
||||
const right = body.motorRight?.direction || '?';
|
||||
const duration = body.durationInSeconds || 0;
|
||||
return c.json({
|
||||
status: 200,
|
||||
message: `Fahre ${left} links und ${right} rechts für ${duration} Sek. 🛞`,
|
||||
received: body,
|
||||
});
|
||||
});
|
||||
|
||||
// Fallback
|
||||
app.all('*', (c) =>
|
||||
c.json({ status: 404, message: 'Endpoint nicht gefunden' }, 404)
|
||||
);
|
||||
|
||||
serve({ fetch: app.fetch, port: 3000 });
|
||||
console.log('🚀 Mockserver läuft auf http://localhost:3000');
|
||||
1
src/robo-project/backend/test.http
Normal file
1
src/robo-project/backend/test.http
Normal file
@ -0,0 +1 @@
|
||||
GET http://localhost:3000/horn/beep
|
||||
12
src/robo-project/backend/tsconfig.json
Normal file
12
src/robo-project/backend/tsconfig.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
@ -6,6 +6,12 @@ GET http://robo-backend.innofera.com/horn/beep
|
||||
### Get Status Light
|
||||
GET http://172.20.10.2/statuslight/state
|
||||
|
||||
### Set Status Light on
|
||||
GET http://172.20.10.2/statuslight/on
|
||||
|
||||
### Set Status Light off
|
||||
GET http://172.20.10.2/statuslight/off
|
||||
|
||||
### POST
|
||||
POST http://172.20.10.2/move
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user