Files
gerbeur/api/lib/static.ts
khannurien 856511777c
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 46s
chore: smaller docker image, simplification pass on environment variables, fix direct navigation without vite
2026-04-08 19:43:19 +00:00

22 lines
603 B
TypeScript

import { Context, Next, send } from "@oak/oak";
export function routeStaticFilesFrom(staticPaths: string[]) {
return async (context: Context<Record<string, object>>, next: Next) => {
for (const path of staticPaths) {
try {
await send(context, context.request.url.pathname, {
root: path,
index: "index.html",
});
return;
} catch {
continue;
}
}
// SPA fallback: serve index.html so client-side routes work on direct navigation
await send(context, "/index.html", { root: staticPaths[0] });
await next();
};
}