From e68652fe4c51ea4c7e3b40f6293a7d2ca8aadce6 Mon Sep 17 00:00:00 2001 From: I9 Date: Wed, 14 Feb 2024 18:08:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=BA=86=20vite=20?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E9=85=8D=E7=BD=AE=EF=BC=8C=20=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E7=8E=AF=E5=A2=83=E4=B8=8B=E5=90=8E=E7=AB=AF=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E8=87=AA=E7=AD=BE=E5=90=8D=E7=9A=84=20https=20?= =?UTF-8?q?=E8=AF=81=E4=B9=A6=E4=B8=8D=E6=8A=A5=E9=94=99=EF=BC=8C=20?= =?UTF-8?q?=E5=BF=BD=E8=A7=86=20Secure=20SameSite=20=E7=AD=89=20cookie=20?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E5=AE=89=E5=85=A8=E6=A3=80=E6=9F=A5=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 7 +++++-- vite.config.ts | 19 ++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/.env.development b/.env.development index 83fd5c5..559a8f7 100644 --- a/.env.development +++ b/.env.development @@ -1,5 +1,8 @@ # 本地环境 ENV = development -# 本地环境接口地址 -VITE_API_URL = http://localhost:8888/ \ No newline at end of file +# https 前面加斜杠,表示通过 vite 代理访问 +VITE_API_URL = '/https://api.example.com' + +# 不加斜杠,表示直接访问,不使用代理 +# VITE_API_URL = 'https://api.example.com' diff --git a/vite.config.ts b/vite.config.ts index 6c2b274..f2d1d9c 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -28,11 +28,24 @@ const viteConfig = defineConfig((mode: ConfigEnv) => { open: JSON.parse(env.VITE_OPEN), hmr: true, proxy: { - '/gitee': { - target: 'https://gitee.com', + [env.VITE_API_URL]: { + target: env.VITE_API_URL.substring(1), ws: true, changeOrigin: true, - rewrite: (path) => path.replace(/^\/gitee/, ''), + rewrite: (path) => path.replace(env.VITE_API_URL, ''), + configure(proxy, options){ + // https://github.com/http-party/node-http-proxy/tree/master + options.secure = false; // https 允许自签名证书 + proxy.on('proxyRes', (proxyRes: any) => { + let cookies = proxyRes.headers['set-cookie']; + if(cookies) { + for(let i in cookies){ + // 开发环境下忽视 cookie https/同源策略 相关安全检查 + cookies[i] = cookies[i].replace(/; *Secure|; *SameSite=\w+/ig, ''); + } + } + }) + } }, }, }, -- Gitee From 4a2591a590896f13cdd300d6f1184cdfe6e16c59 Mon Sep 17 00:00:00 2001 From: I9 Date: Wed, 14 Feb 2024 21:43:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=BA=86=20pinia=20?= =?UTF-8?q?=E7=9A=84=E5=AE=9A=E4=B9=89=E5=92=8C=E5=AF=BC=E5=85=A5=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 14 +++++--------- src/i18n/index.ts | 16 +++++----------- src/layout/component/aside.vue | 9 +++------ src/layout/component/header.vue | 3 +-- src/layout/component/main.vue | 6 ++---- src/layout/index.vue | 3 +-- src/layout/main/defaults.vue | 3 +-- src/layout/navBars/index.vue | 3 +-- src/layout/navBars/tagsView/tagsView.vue | 15 +++++---------- src/layout/navBars/topBar/breadcrumb.vue | 6 ++---- src/layout/navBars/topBar/closeFull.vue | 3 +-- src/layout/navBars/topBar/index.vue | 6 ++---- src/layout/navBars/topBar/search.vue | 3 +-- src/layout/navBars/topBar/setings.vue | 3 +-- src/layout/navBars/topBar/user.vue | 3 +-- src/layout/navMenu/vertical.vue | 3 +-- src/layout/routerView/parent.vue | 6 ++---- src/layout/upgrade/index.vue | 3 +-- src/main.ts | 13 +++++++++---- src/router/backEnd.ts | 17 +++++++---------- src/router/frontEnd.ts | 15 ++++++--------- src/router/index.ts | 10 +++------- src/stores/index.ts | 8 -------- src/stores/keepAliveNames.ts | 4 +++- src/stores/pinia.ts | 6 ++++++ src/stores/requestOldRoutes.ts | 4 +++- src/stores/routesList.ts | 4 +++- src/stores/tagsViewRoutes.ts | 4 +++- src/stores/themeConfig.ts | 4 +++- src/utils/other.ts | 5 +---- src/views/login/component/account.vue | 3 +-- src/views/login/index.vue | 3 +-- 32 files changed, 85 insertions(+), 123 deletions(-) delete mode 100644 src/stores/index.ts create mode 100644 src/stores/pinia.ts diff --git a/src/App.vue b/src/App.vue index 8007417..d5a5552 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,9 +1,9 @@