8fa6f795c0
- Replace old JS backend with working TypeScript backend from deployed containers - Backend: Fastify + better-sqlite3 + Yjs CRDT, 17 TS source files, 13 test files - Frontend: React JSX with fabric.js CAD canvas, vite build, nginx serving - Fix nginx proxy port 5000→3001 to match backend - Fix docker-compose port mapping 5000→3001 - Fix vite dev proxy port 5000→3001 - Add backend healthcheck to docker-compose - Update index.html title to 'Web CAD', lang to 'de' - Add .a0/ to .gitignore - Remove old JS backend files (models, routes, config, middleware, seed) - Remove tracked build artifacts (backend/public/)
27 lines
988 B
TypeScript
27 lines
988 B
TypeScript
/**
|
||
* Settings Routes – key/value application settings
|
||
*/
|
||
import type { FastifyInstance } from 'fastify';
|
||
import type { DatabaseInterface } from '../database/DatabaseInterface.js';
|
||
|
||
export function registerSettingsRoutes(fastify: FastifyInstance, db: DatabaseInterface) {
|
||
// Get a single setting by key
|
||
fastify.get('/api/settings/:key', async (request, reply) => {
|
||
const { key } = request.params as { key: string };
|
||
const setting = db.getSetting(key);
|
||
if (!setting) return reply.code(404).send({ error: 'Setting not found' });
|
||
return setting;
|
||
});
|
||
|
||
// Create or update a setting (upsert)
|
||
fastify.put('/api/settings/:key', async (request) => {
|
||
const { key } = request.params as { key: string };
|
||
const body = request.body as { value?: string };
|
||
if (body.value === undefined) {
|
||
return { error: 'Value is required' };
|
||
}
|
||
db.setSetting(key, body.value);
|
||
return { key, value: body.value, updated_at: new Date().toISOString() };
|
||
});
|
||
}
|