Skip to main content
Module

x/fastro/examples/use_middleware.ts

Fast and simple web application framework for deno
Go to Latest
File
import { Fastro, Request } from "../mod.ts";import { sendOk, support } from "../middleware/mod.ts";
const server = new Fastro();
// you may not send a response more than once in a requestfunction sendHi(req: Request) { if (false) return req.send("Hello");}
// add middleware to serverserver .use(sendHi) // add sendOk middleware from external file .use(sendOk) // add support middleware from external file .use(support);
server // use sendOk middleware .get("/", (req) => req.sendOk("hello")) .post("/:hello", (req) => { // access custom send function req.sendOk("ok deh"); });
await server.listen({ port: 8000 });