我在expressjs中使用了如下配置,在nestjs中如何使用?

I use the following configuration in expressjs, how to use it in nestjs?

在nestjs中直接使用会出现错误

app.get('*', function (request, response){
  response.sendFile(path.resolve(__dirname, 'public', 'index.html'))
})

我不知道这是否正确,但它达到了我的目的。

  app.use((req, res) => {
    if (req.method === 'GET') {
      res.sendFile(
        path.resolve(__dirname, '..', 'public', 'build', 'index.html'),
      );
    }
  });

你可以使用中间件,然后应用GET方法:

export class ApplicationModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(YourMiddleware)
      .forRoutes({ path: '*', method: RequestMethod.Get });
  }
}