All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 46s
22 lines
603 B
TypeScript
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();
|
|
};
|
|
}
|