import { type Fastro } from "https://deno.land/x/fastro@v0.77.3/http/server.ts";
Methods
use(...handler: Array<HandlerArgument>): Fastro
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();
get(path: string, ...handler: Array<HandlerArgument>): Fastro
post(path: string, ...handler: Array<HandlerArgument>): Fastro
put(path: string, ...handler: Array<HandlerArgument>): Fastro
delete(path: string, ...handler: Array<HandlerArgument>): Fastro
patch(path: string, ...handler: Array<HandlerArgument>): Fastro
options(path: string, ...handler: Array<HandlerArgument>): Fastro
head(path: string, ...handler: Array<HandlerArgument>): Fastro
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();
static(path: string, options?: { maxAge?: number; folder?: string; }): Fastro
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();
push(): Fastro
method?: string,
path?: string,
...handler: Array<HandlerArgument>,
Add a handler directly