【发布时间】:2021-10-12 10:46:11
【问题描述】:
我使用 NestJs 作为后端服务器,使用 Angular 作为前端 我在 pc 上使用 chrome 时没问题,我可以满足我的所有要求 但是当我将我的 android chrome 与 DevTools 一起使用时,我收到了这个错误
消息:“http://localhost:3000/users/login 的 Http 失败响应:0 未知错误”
这是错误消息的快照 enter image description here
如果我没有在 NestJs 上打开 CORS,它也会发送与 pc chrome 相同的错误
这是我的 COSR 配置
import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { NextFunction, Request, Response } from 'express';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.use((req: Request, res: Response, next: NextFunction) => {
console.log(req);
next();
});
app.useGlobalPipes(new ValidationPipe());
app.enableCors({
origin: true,
methods: ['GET', 'PUT', 'POST', 'DELETE'],
exposedHeaders: ['x-auth'],
});
await app.listen(3000);
}
bootstrap();
顺便说一句,当我在我的 Nest 应用程序上记录请求时 我没有收到任何请求 我认为 NestJs 立即拒绝了它
【问题讨论】:
-
这能回答你的问题吗? NestJS enable cors in production
标签: node.js angular express nestjs