From 22407b01be4142ee9458959d52190542e6344cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=BE=E9=A3=8E?= <45625953+an501920078@users.noreply.github.com> Date: Mon, 30 Oct 2023 08:50:39 +0800 Subject: [PATCH] Update index.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加请求时的跨域头部,便于微前端服务请求 --- src/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index ff4ba25..fd3ddba 100644 --- a/src/index.ts +++ b/src/index.ts @@ -74,7 +74,11 @@ export default function vitePluginCesium(options: VitePluginCesiumOptions = {}): configureServer({ middlewares }) { const cesiumPath = path.join(cesiumBuildRootPath, devMinifyCesium ? 'Cesium' : 'CesiumUnminified'); - middlewares.use(path.posix.join('/', CESIUM_BASE_URL), serveStatic(cesiumPath)); + middlewares.use(path.posix.join('/', CESIUM_BASE_URL), serveStatic(cesiumPath, { + setHeaders: (res, path, stat) => { + res.setHeader('Access-Control-Allow-Origin', '*') + } + })); }, async closeBundle() {