From 54046a4717d63dcc0f988924f631360b0ced2188 Mon Sep 17 00:00:00 2001 From: InfinityPacer <160988576+InfinityPacer@users.noreply.github.com> Date: Thu, 10 Oct 2024 15:41:02 +0800 Subject: [PATCH] feat(vite): add server proxy to handle CORS for API requests --- .env.development | 2 +- vite.config.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.env.development b/.env.development index 2f3084f9..1b26ff69 100644 --- a/.env.development +++ b/.env.development @@ -1,2 +1,2 @@ -VITE_API_BASE_URL=http://localhost:3001/api/v1/ +VITE_API_BASE_URL=/api/v1/ VITE_PUBLIC_VAPID_KEY=BH3w49sZA6jXUnE-yt4jO6VKh73lsdsvwoJ6Hx7fmPIDKoqGiUl2GEoZzy-iJfn4SfQQcx7yQdHf9RknwrL_lSM diff --git a/vite.config.ts b/vite.config.ts index e9f9377a..d4f8cfbb 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -151,4 +151,14 @@ export default defineConfig({ exclude: ['vuetify'], entries: ['./src/**/*.vue'], }, + server: { + proxy: { + '/api/v1': { + target: 'http://localhost:3001', + changeOrigin: true, + secure: false, + cookieDomainRewrite: 'localhost', + }, + }, + }, })