CORS 策略已阻止从源“ http://localhost:4200 ”访问“localhost:3000”处的 XMLHttpRequest :跨源请求仅支持协议方案:http、data、chrome、chrome-extension、https。
core.js:7187 错误 HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: "localhost:3000", ok: false, ...}
1. var app = await NestFactory.create(AppModule,{cors:true}); 等待 app.listen(3000);
var app = await NestFactory.create(AppModule); const options = { origin: '*', methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', preflightContinue: false, optionsSuccessStatus: 204, credentials: true, allowedHeaders: 'Content-Type, Accept', }; 控制台日志(应用程序);app.enableCors(选项); 等待 app.listen(3000);
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app/app.module';
async function bootstrap() …Run Code Online (Sandbox Code Playgroud)nestjs ×1