【发布时间】:2018-10-24 11:09:35
【问题描述】:
直接在nestjs中使用会报错
app.get('*', function (request, response){
response.sendFile(path.resolve(__dirname, 'public', 'index.html'))
})
【问题讨论】:
标签: nestjs
直接在nestjs中使用会报错
app.get('*', function (request, response){
response.sendFile(path.resolve(__dirname, 'public', 'index.html'))
})
【问题讨论】:
标签: nestjs
您可以使用中间件,然后应用 GET 方法:
export class ApplicationModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(YourMiddleware)
.forRoutes({ path: '*', method: RequestMethod.Get });
}
}
【讨论】:
我不知道这是否正确,但它已经达到了我的目标。
app.use((req, res) => {
if (req.method === 'GET') {
res.sendFile(
path.resolve(__dirname, '..', 'public', 'build', 'index.html'),
);
}
});
【讨论】: