Static
Static<
T>(options,prefix):Middleware
Defined in: src/plugins/middleware/static.ts:31
Creates a static file serving middleware that falls through to the next handler when files are not found, instead of returning 404.
This is useful for scenarios where you want to serve static files first, but fall back to a route handler if the file doesn’t exist.
Type Parameters
Section titled “Type Parameters”T extends Record<string, any>
Parameters
Section titled “Parameters”options
Section titled “options”Static serve options or root directory path
string | StaticServeOptions<T>
prefix
Section titled “prefix”string = '/'
URL prefix to strip from paths (defaults to ’/‘)
Returns
Section titled “Returns”Middleware that serves static files or calls next()
Example
Section titled “Example”// Basic usage - serves files from ./distrouter.get('/app', Static({ root: './dist' }), async (ctx) => { // This handler only runs if no static file was found return ctx.html(await renderSPA());});
// With custom optionsrouter.get('/assets', Static({ root: './public', etag: true, maxAge: 3600}), ctx => ctx.text('Asset not found'));