Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fsrouter/mod.ts>FsHandler

A file system based router for Deno.
Latest
type alias FsHandler
import { type FsHandler } from "https://deno.land/x/fsrouter@3.1.0/mod.ts";

Every file to which routes are being served must export a function of type FsHandler as its default export. FsHandler is very similar to the standard library Handler type -- the first argument is a Request object, the second argument is of type Slugs, and the third argument is the standard library type ConnInfo. The Slugs argument is placed as the second argument instead of the third for better ergonomics. See example below for more details.

import { type FsHandler } from "https://deno.land/x/fsrouter@{VERSION}/handler.ts"

// The slugs object here contains any matched text from route wildcards.
// For example, if this handler was defined in the file '/[id].ts' and the
// server was hit with the route '/hello', the query object would be of the shape
// { id: 'hello' }
const handler: FsHandler = (_req, slugs) => {
  return new Response(`/${slugs.id}`);
};

export default handler;
definition: (
request: Request,
slugs: Slugs,
connInfo: http.ConnInfo,
) => Response | Promise<Response>
definition: (
request: Request,
slugs: Slugs,
connInfo: http.ConnInfo,
) => Response | Promise<Response>