User codes
This commit is contained in:
@@ -1,30 +1,16 @@
|
||||
import { App, staticFiles } from "fresh";
|
||||
import { App, csp, csrf, staticFiles } from "fresh";
|
||||
import { define, type State } from "./utils.ts";
|
||||
|
||||
export const app = new App<State>();
|
||||
|
||||
// Vite's dev client injects CSS through <style> tags without a nonce
|
||||
app.use(csrf(), csp({ useNonce: !import.meta.env.DEV }));
|
||||
|
||||
app.use(staticFiles());
|
||||
|
||||
// Pass a shared value from a middleware
|
||||
app.use(async (ctx) => {
|
||||
ctx.state.shared = "hello";
|
||||
return await ctx.next();
|
||||
});
|
||||
|
||||
// this is the same as the /api/:name route defined via a file. feel free to delete this!
|
||||
app.get("/api2/:name", (ctx) => {
|
||||
const name = ctx.params.name;
|
||||
return new Response(
|
||||
`Hello, ${name.charAt(0).toUpperCase() + name.slice(1)}!`,
|
||||
);
|
||||
});
|
||||
|
||||
// this can also be defined via a file. feel free to delete this!
|
||||
const exampleLoggerMiddleware = define.middleware((ctx) => {
|
||||
app.use(define.middleware((ctx) => {
|
||||
console.log(`${ctx.req.method} ${ctx.req.url}`);
|
||||
return ctx.next();
|
||||
});
|
||||
app.use(exampleLoggerMiddleware);
|
||||
}));
|
||||
|
||||
// Include file-system based routes here
|
||||
app.fsRoutes();
|
||||
|
||||
Reference in New Issue
Block a user