From 57add80c409eda80ea3ae087c446bacf9164a391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=9E=97?= <1570898673@qq.com> Date: Sun, 13 Apr 2025 15:13:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E8=B7=A8=E5=9F=9F?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main.ts b/src/main.ts index 72b46c8..29b9a39 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,6 +16,16 @@ async function bootstrap() { app.useGlobalPipes(new ValidationPipe()); app.setGlobalPrefix('api'); + // 配置CORS + app.enableCors({ + origin: '*', // 允许所有来源 + methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', // 允许的HTTP方法 + credentials: true, // 允许携带凭证(如cookies) + allowedHeaders: 'Content-Type,Authorization', // 允许的头部字段 + exposedHeaders: 'Content-Type,Authorization', // 暴露的头部字段 + maxAge: 3600, // 预检请求的缓存时间,单位为秒 + }); + await app.listen(PORT); console.log('正在监听端口:', PORT); } catch (error) {