Skip to content

Commit

Permalink
fix: resolve path correctly, make headers compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
tinfoil-knight authored and danez committed Jan 3, 2023
1 parent 72f5685 commit f62b4f4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/commands/dev/dev.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ const netlifyBuildPromise = import('@netlify/build')

const startStaticServer = async ({ settings }) => {
const server = Fastify()
const rootPath = path.resolve(settings.dist)
server.register(fastifyStatic, {
root: path.resolve(settings.dist),
// eslint-disable-next-line no-unused-vars
setHeaders: (res, _path, _stat) => {
res.setHeader('X-Powered-by', 'netlify-dev')
},
root: rootPath,
etag: false,
acceptRanges: false,
lastModified: false,
})

server.setNotFoundHandler((_req, res) => {
res.code(404).sendFile('404.html', settings.dist)
res.code(404).sendFile('404.html', rootPath)
})

server.addHook('onRequest', (req, reply, done) => {
reply.header('X-Powered-by', 'netlify-dev')
const validMethods = ['GET', 'HEAD']
if (!validMethods.includes(req.method)) {
reply.code(405).send('Method Not Allowed')
Expand Down

0 comments on commit f62b4f4

Please sign in to comment.