x/fastro/docs/handler.md
fastro init command will generate folders and files like this.
fastro init
webapp ├── Dockerfile ├── middleware │ └── support.ts ├── public │ ├── favicon.ico │ ├── index.html │ └── logo.svg └── services ├── hello.controller.ts └── hello.template.html 3 directories, 7 files
File and folder description:
Dockerfile
middleware
public
services
Open handler file, services/hello.controller.ts:
services/hello.controller.ts
import type { Request } from "https://raw.fastro.dev/master/mod.ts"; export const handler = (request: Request) => { // request.view("hello.template.html", { greeting: "Hello", name: "World" }); request.send(`setup ${request.hello}`); };
Please note that:
the handler file name will be used as URL endpoint:
request.hello variable is come from middleware.
request.hello
You can find another handler examples on services folder.
Run server
With fastro-cli
fastro serve
Or with entrypoint
deno run -A main.ts
Open url to access the handler
http://localhost:3000/hello