NestJS:现有路由上找不到404错误

时间:2019-03-13 14:14:51

标签: node.js express nestjs

如果我发布到NestJS应用程序的现有路由,则会收到404错误。 奇怪的是,如果验证失败,则请求可以正常工作。

即空正文或正文中缺少数据的POST请求返回到我的路线,返回:

{
    "error": "Validation failed",
    "validationErrors": {
        "email": [
            "Email can't be blank"
        ]
    },
    "status": 400
}

包含所有必需数据的请求将返回404错误。

错误堆栈跟踪:

{ Error: [object Object]
    at callback (/Users/matthias/Dev/Git/sf-nest-server/node_modules/@nestjs/core/router/routes-resolver.js:43:19)
    at /Users/matthias/Dev/Git/sf-nest-server/node_modules/@nestjs/core/router/router-proxy.js:8:23
    at Layer.handle [as handle_request] (/Users/matthias/Dev/Git/sf-nest-server/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/matthias/Dev/Git/sf-nest-server/node_modules/express/lib/router/index.js:317:13)
    at /Users/matthias/Dev/Git/sf-nest-server/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/Users/matthias/Dev/Git/sf-nest-server/node_modules/express/lib/router/index.js:335:12)
    at Immediate.next (/Users/matthias/Dev/Git/sf-nest-server/node_modules/express/lib/router/index.js:275:10)
    at Immediate.<anonymous> (/Users/matthias/Dev/Git/sf-nest-server/node_modules/express/lib/router/index.js:635:15)
    at runCallback (timers.js:796:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)

app.ts

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ErrorFilter } from './errors/error.filter';
import { Logger } from '@nestjs/common';

import * as bodyParser from 'body-parser';
import * as Superlogin from 'superlogin';

import * as usersSuperloginConfig from '@config/superlogin-users';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.enableCors();

  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));

  if (process.env.NODE_ENV !== 'production') {
    require('dotenv').load();
  }
  const usersSuperlogin = new Superlogin(usersSuperloginConfig);
  app.use('/users/auth', usersSuperlogin.router);

  usersSuperlogin.on('signup', (userDoc, provider) => {
    Logger.log(userDoc);

  });

  app.setViewEngine('ejs');
  app.useGlobalFilters(new ErrorFilter());
  app.setBaseViewsDir(__dirname + '/views');

  await app.listen(process.env.PORT);
  Logger.log(`Listening on Port ${process.env.PORT}`);
}

bootstrap();

可能是什么问题?

0 个答案:

没有答案