28 lines
791 B
TypeScript
28 lines
791 B
TypeScript
import { App, csp, csrf, staticFiles } from "fresh";
|
|
|
|
import { define, type State } from "./utils.ts";
|
|
import { UPLOAD_CSP } from "@/src/storage.ts";
|
|
|
|
export const app = new App<State>();
|
|
|
|
// csp() overwrites any policy a route sets, so the stricter one for uploaded files is put back here
|
|
app.use(define.middleware(async (ctx) => {
|
|
const res = await ctx.next();
|
|
if (res.headers.get("Content-Disposition") === "attachment") {
|
|
res.headers.set("Content-Security-Policy", UPLOAD_CSP);
|
|
}
|
|
return res;
|
|
}));
|
|
|
|
// Vite's dev client injects CSS through <style> tags without a nonce
|
|
app.use(csrf(), csp({ useNonce: !import.meta.env.DEV }));
|
|
|
|
app.use(staticFiles());
|
|
|
|
app.use(define.middleware((ctx) => {
|
|
console.log(`${ctx.req.method} ${ctx.req.url}`);
|
|
return ctx.next();
|
|
}));
|
|
|
|
app.fsRoutes();
|