* @param {string} path * @param {boolean} client
(path, client = false)
| 44 | * @param {boolean} client |
| 45 | */ |
| 46 | function serve(path, client = false) { |
| 47 | return ( |
| 48 | fs.existsSync(path) && |
| 49 | sirv(path, { |
| 50 | etag: true, |
| 51 | gzip: true, |
| 52 | brotli: true, |
| 53 | setHeaders: |
| 54 | client && |
| 55 | ((res, pathname) => { |
| 56 | // only apply to build directory, not e.g. version.json |
| 57 | if (pathname.startsWith(`/${manifest.appPath}/immutable/`) && res.statusCode === 200) { |
| 58 | res.setHeader('cache-control', 'public,max-age=31536000,immutable'); |
| 59 | } |
| 60 | }) |
| 61 | }) |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | // required because the static file server ignores trailing slashes |
| 66 | /** @returns {import('polka').Middleware} */ |
no outgoing calls
no test coverage detected