Configuring the FileSystemRouter
FileSystemRouterOptions
Here is an extended example on how to configure the file system router.
origin
origin
: Origin used for the request, by default uses theprocess.env.ORIGIN
. On the web version, this is not needed because theorigin
is determined from the request.
cwd
cwd
: The absolute path of the working directory, defaults toprocess.cwd()
.
routesDir
routesDir
: The path where the routes are located, relative to thecwd
, defaults tosrc/routes/
.
middleware
middleware
: The name of the middleware, defaults tomiddleware
.
notFound
notFound
: The name of the file used for 404 handling, defaults to404
.
prefix
prefix
: A prefix used for all the routes.
routeMapper
routeMapper
: A class that maps a file-system path to a route, the default uses aNextJS
like routing.
extensions
extensions
: Extensions of valid routes, defaults to["js", "jsx", "cjs", "mjs", "ts", "tsx", "cts", "mts"]
.
ignorePrefix
ignorePrefix
: A prefix used for ignore files or directories, defaults to_
.
ignoreFiles
ignoreFiles
: A glob of files to ignore.
getLocals
getLocals
: A function to initialize the request locals, this runs even before the middleware.
workers
workers
: Controls the worker threads, by default this is not enabled.
You can pass true
which will spawn workers threads up to the number of logical processors,
or specify a number of workers. This workers are spawned in a pool and reused.