Created
June 8, 2021 07:06
-
-
Save madbonez/98705003dc387e2e13ff50b00210aea2 to your computer and use it in GitHub Desktop.
fastify settings for SPA serve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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