Module
x/fastro/docs/route-middleware.md
Full Stack Framework for Deno, TypeScript, Preact JS and Tailwind CSS
Latest
https://fastro.deno.dev/fastro.png previous: route-middleware next: markdown
title: “Route Middleware” description: The application that use route middleware image:import fastro, { Context, HttpRequest } from "https://fastro.deno.dev/mod.ts";
const f = new fastro();
const m1 = (req: HttpRequest, ctx: Context) => {
// console.log("middleware 1");
req.m1 = "middleware1";
return ctx.next();
};
const m2 = (_req: HttpRequest, ctx: Context) => {
// console.log("middleware 2");
return ctx.next();
};
const m3 = (_req: HttpRequest, ctx: Context) => {
// console.log("middleware 3");
return ctx.next();
};
const m4 = (_req: HttpRequest, ctx: Context) => {
// console.log("middleware 4");
return ctx.next();
};
const handler = (req: HttpRequest) => {
// `middleware1` for get
// `undefined` for post
return req.m1;
};
f.get("/", m1, m2, m3, handler);
f.post("/", m4, handler);
await f.serve();