配置:
const indexTemplate = readFileSync(assetsPath + '/index.html', {encoding: 'utf-8'});
let compiled = Handlebars.compile(indexTemplate);
const indexHandler = async (request: FastifyRequest, reply: FastifyReply) => {
let indexHtml = await app.ioredis.get('index.html');
if (indexHtml == null) {
indexHtml = compiled({env: process.env['APP_ENV']});
await app.ioredis.setex('index.html', 300, indexHtml);
}
return reply.type('text/html').send(indexHtml);
}
app.get('/', indexHandler);
app.setNotFoundHandler(indexHandler);
想了解更多关于Fastify SPA 路由配置的内容,请扫微信
或微信搜索jiemingpan
版权说明:本文版权由作者自行负责,如有侵权请联系本站删除。