From 527b70122d87a08465c93691cf81259adb7d9caa Mon Sep 17 00:00:00 2001 From: Sirttas Date: Wed, 26 Jul 2023 13:52:08 +0200 Subject: [PATCH] fix env --- .env.development | 4 ++-- src/service.ts | 7 ++++-- vite.config.ts | 58 +++++++++++++++++++++++++++--------------------- 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/.env.development b/.env.development index ff46f0b..433f0cd 100644 --- a/.env.development +++ b/.env.development @@ -1,2 +1,2 @@ -eveal_api_url=/api/ -evepraisal_api_url=/appraisal/ \ No newline at end of file +EVEAL_API_URL=/api/ +EVEPRAISAL_URL=/appraisal/ \ No newline at end of file diff --git a/src/service.ts b/src/service.ts index 068a826..ea415b9 100644 --- a/src/service.ts +++ b/src/service.ts @@ -1,7 +1,10 @@ import axios from 'axios'; +const evealApiUrl = process.env.EVEAL_API_URL; +const evepraisalUrl = process.env.EVEPRAISAL_URL; + export const apiAxiosInstance = axios.create({ - baseURL: '/api/', + baseURL: evealApiUrl, headers: { 'accept': 'application/json', "Content-Type": "application/json" @@ -9,7 +12,7 @@ export const apiAxiosInstance = axios.create({ }) export const evepraisalAxiosInstance = axios.create({ - baseURL: '/appraisal/', + baseURL: evepraisalUrl, headers: { 'accept': 'application/json', "Content-Type": "application/json" diff --git a/vite.config.ts b/vite.config.ts index 8b3e280..78c7c04 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,32 +1,40 @@ import vue from '@vitejs/plugin-vue'; import * as path from "path"; -import { defineConfig } from 'vite'; +import { defineConfig, loadEnv } from 'vite'; -export default defineConfig({ - plugins: [vue()], - resolve: { - alias: { - 'src': path.resolve(__dirname, './src/'), - '@': path.resolve(__dirname, './src/'), - }, - extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'] - }, - server: { - port: 3000, - strictPort: true, - proxy: { - '/api/': { - target: 'https://api.eveal.shendai.rip/', - changeOrigin: true, - followRedirects: true, - rewrite: (path) => path.replace(/^\/api/, ''), +export default defineConfig(({ mode }) => { + const env = loadEnv(mode, process.cwd(), ''); + + return { + plugins: [vue()], + resolve: { + alias: { + 'src': path.resolve(__dirname, './src/'), + '@': path.resolve(__dirname, './src/'), }, - '/appraisal/': { - target: 'https://evepraisal.shendai.rip/', - changeOrigin: true, - followRedirects: true, - rewrite: (path) => path.replace(/^\/appraisal/, ''), + extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'] + }, + define: { + 'process.env.EVEAL_API_URL': JSON.stringify(env.EVEAL_API_URL), + 'process.env.EVEPRAISAL_URL': JSON.stringify(env.EVEPRAISAL_URL), + }, + server: { + port: 3000, + strictPort: true, + proxy: { + '/api/': { + target: 'https://api.eveal.shendai.rip/', + changeOrigin: true, + followRedirects: true, + rewrite: (path) => path.replace(/^\/api/, ''), + }, + '/appraisal/': { + target: 'https://evepraisal.shendai.rip/', + changeOrigin: true, + followRedirects: true, + rewrite: (path) => path.replace(/^\/appraisal/, ''), + } } } - }, + }; })