packages/static-middleware/README.md
Static file serving middleware for Remix. Serves static files from a directory with support for ETags, range requests, and conditional requests.
npm i remix
Static middleware is useful for serving static files from a directory.
import { createRouter } from 'remix/fetch-router'
import { staticFiles } from 'remix/static-middleware'
let router = createRouter({
middleware: [staticFiles('./public')],
})
router.get('/', () => new Response('Home'))
Internally, the staticFiles() middleware uses the createFileResponse() helper from @remix-run/response to send files with full HTTP semantics. This means it also accepts the same options as the createFileResponse() helper.
let router = createRouter({
middleware: [
staticFiles('./public', {
cacheControl: 'public, max-age=31536000, immutable', // 1 year
}),
],
})
let router = createRouter({
middleware: [
staticFiles('./public', {
filter(path) {
// Don't serve hidden files
return !path.startsWith('.')
},
}),
],
})
let router = createRouter({
middleware: [
staticFiles('./public'),
staticFiles('./assets', {
cacheControl: 'public, max-age=31536000',
}),
],
})
../../../etc/passwd)fetch-router - Router for the web Fetch APIlazy-file - Used internally for streaming file contentsSee LICENSE