I have the following front end middleware:
export class FrontendMiddleware implements NestMiddleware {
use(req: any, res: any, next: () => void) {
const url = req.originalUrl;
if (url.indexOf('rest') === 1) {
next();
} else if (allowedExt.filter(ext => url.indexOf(ext) > 0).length > 0) {
res.sendFile(resolvePath(url));
} else {
res.sendFile(resolvePath('index.html'));
}
}
}
It works fine with express, but with fastify, res.sendFile
is undefined
, so how can I fix that?
Have a look at this issue. sendFile
has no equivalent method in fastify; you have to do it manually:
const stream = fs.createReadStream(resolvePath('index.html'))
res.type('text/html').send(stream)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With