From 627806fda5bf52356e4a0f42dc1946c444a8522b Mon Sep 17 00:00:00 2001 From: Agent Date: Tue, 14 Jul 2026 19:28:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20CORP=20=E5=A4=B4=20same-origin=20?= =?UTF-8?q?=E9=98=BB=E6=AD=A2=20crossorigin=20=E8=84=9A=E6=9C=AC=EF=BC=8C?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=20cross-origin=20=E5=85=81=E8=AE=B8=E5=90=8C?= =?UTF-8?q?=E6=BA=90=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/index.js | 4 +++- frontend/vite.config.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/src/index.js b/backend/src/index.js index b56b40f..7d530dc 100644 --- a/backend/src/index.js +++ b/backend/src/index.js @@ -9,7 +9,9 @@ import { authenticate } from './middleware/auth.js'; const app = express(); const PORT = process.env.PORT || 3000; -app.use(helmet()); +app.use(helmet({ + crossOriginResourcePolicy: { policy: 'cross-origin' }, +})); app.use(cors()); app.use(express.json()); diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 9e2b07c..49f6758 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -7,7 +7,7 @@ export default defineConfig({ resolve: { alias: { '@': resolve(__dirname, 'src') } }, build: { rollupOptions: { - output: { crossOrigin: false }, // 禁用 crossorigin,避免 helmet 无 CORS 头导致 JS 被阻止 + output: { crossOrigin: null }, // 完全移除 crossorigin 属性 }, }, server: { port: 5173, proxy: { '/api': { target: 'http://localhost:3000', changeOrigin: true } } },