20 lines
451 B
TypeScript
20 lines
451 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;
|
|
}
|
|
}
|
|
|
|
await next();
|
|
};
|
|
}
|