import { type Fastro } from "https://deno.land/x/fastro@v0.77.3/mod.ts";
Methods
Add application level middleware
Example
import fastro from "../mod.ts";
const f = new fastro();
f.use((req: HttpRequest, _ctx: Context, next: Next) => {
console.log(`${req.method} ${req.url}`);
return next();
});
await f.serve();
Allow you access Server, Request, and Info after Middleware, Routes, Pages, and Static File Processing.
It can return Response
, Promise<Response>
or void
.
Example
import fastro, { Fastro, Info } from "../mod.ts";
const f = new fastro();
f.hook((_f: Fastro, _r: Request, _i: Info) => new Response("Hello World"));
await f.serve();
Allow you to access static files with custom path
, folder
, and maxAge
Example
import fastro from "../mod.ts";
const f = new fastro();
f.static("/static", { folder: "static", maxAge: 90 });
await f.serve();
Allow you to define SSR page with custom path
, element
, and handler
Example
import fastro, { Context, HttpRequest } from "../mod.ts";
import user from "../pages/user.tsx";
const f = new fastro();
f.static("/static", { folder: "static", maxAge: 90 });
f.page("/", user, (_req: HttpRequest, ctx: Context) => {
const options = {
props: { data: "Guest" },
status: 200,
html: { head: { title: "React Component" } },
};
return ctx.render(options);
},
);
await f.serve();
Add a handler directly