我正在尝试使用javascript在Nestjs中编写中间件

问题描述 投票:0回答:1

但是出了点问题。我有一个错字。你能帮我吗?

应用程序模块

export class AppModule extends NestMiddleware {
   configure(consumer) {
      consumer
        .apply(ApiTokenCheckMiddleware)
        .forRoutes({ path: '*', method: RequestMethod.ALL });
      }
   }

中间件

import { NestMiddleware } from "../../../node_modules/@nestjs/common/index";

const express = require("express");
const app = express();
app.use("/", (req, res, next) => {
      console.log(req.headers);
});   
javascript express nestjs middleware
1个回答
0
投票
throw err;
nest-container  |     ^
nest-container  |
nest-container  | SyntaxError: /app/src/app.module.js: Identifier 

“AppModule”已经声明。 (26:13) 巢容器 | 巢容器 | 24 |提供商:[应用程序服务], 巢容器 | 25 | 25 }) 巢容器 | > 26 |导出类 AppModule 扩展 NestMiddleware {
巢容器 | | ^ 巢容器 | 27 | 27配置(消费者){ 巢容器 | 28 | 28消费者 巢容器 | 29 | 29 .apply(ApiTokenCheckMiddleware) 代码:'BABEL_PARSE_ERROR', 巢容器 | ReasonCode: 'VarRedeclaration', 巢容器 | loc: 位置 { 行: 26, 列: 13, 索引: 874 },
巢容器 |职位:874 巢容器 | 巢容器 | Node.js v20.12.2 巢容器 | [nodemon] 应用程序崩溃 - 之前等待文件更改 开始...

© www.soinside.com 2019 - 2024. All rights reserved.