Skip to content

Instantly share code, notes, and snippets.

@madbonez
Created June 8, 2021 07:06
Show Gist options
  • Save madbonez/98705003dc387e2e13ff50b00210aea2 to your computer and use it in GitHub Desktop.
Save madbonez/98705003dc387e2e13ff50b00210aea2 to your computer and use it in GitHub Desktop.
fastify settings for SPA serve
const fastify = require('fastify')()
const path = require('path')
fastify.register(require('fastify-static'), {
root: path.join(__dirname, 'dist'),
})
fastify.setNotFoundHandler(function (request, reply) {
reply.sendFile('index.html')
})
// Run the server!
fastify.listen(4000, function (err, address) {
if (err) {
fastify.log.error(err)
process.exit(1)
}
fastify.log.info(`server listening on ${address}`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment