Plugin for serving static file
- scan the folder and register each file separately. (Instead of
{prefix}/*
) - let system 404 handler handle the NOT FOUND situation
npm install --save fastify-static-xh
const fastify = require('fastify')
const path = require('path')
fastify.register(require('fastify-static-xh'), {
root: path.join(__dirname, 'public'),
prefix: '/public/' // optional: default '/'
})
fastify.get('/another/path', function (req, reply) {
reply.sendFile('myHtml.html') // serving path.join(__dirname, 'public', 'myHtml.html') directly
})
Licensed under MIT