feat(server): add persistent authentication and production build (#6)

Protect HTTP and WebSocket API routes with scrypt password login and signed persistent sessions. Restrict forwarded identity and HTTPS detection to configured proxies, and serve optional web assets with SPA fallback.

Add @fastify/static for Fastify-compatible static file handling and esbuild to bundle TypeScript core source while retaining native dependencies externally.
This commit is contained in:
Florian Schmidt
2026-11-16 00:07:18 +01:00
parent d06f4336ae
commit af331177ac
10 changed files with 817 additions and 3 deletions
+15
View File
@@ -0,0 +1,15 @@
import { existsSync } from "node:fs";
import { resolve } from "node:path";
import type { FastifyInstance } from "fastify";
import fastifyStatic from "@fastify/static";
export async function registerStatic(app: FastifyInstance, directory: string): Promise<void> {
const root = resolve(directory);
if (!existsSync(resolve(root, "index.html"))) return;
await app.register(fastifyStatic, { root, wildcard: false });
app.setNotFoundHandler((request, reply) => {
const path = request.url.split("?")[0]!;
if (path === "/api" || path.startsWith("/api/") || !["GET", "HEAD"].includes(request.method)) return reply.code(404).send({ error: "Not found" });
return reply.type("text/html").sendFile("index.html");
});
}