【问题标题】:I use the following configuration in expressjs, how to use it in nestjs?我在expressjs中使用如下配置,在nestjs中如何使用呢?
【发布时间】:2018-10-24 11:09:35
【问题描述】:

直接在nestjs中使用会报错

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

【问题讨论】:

    标签: nestjs


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-16
        • 2023-02-02
        • 2020-09-22
        • 2019-10-07
        • 2019-05-19
        • 1970-01-01
        • 1970-01-01
        • 2020-09-05
        相关资源
        最近更新 更多