Просмотр исходного кода

feat(http): baseUrl 对接 VITE_SERVER_BASEURL

Burt 2 лет назад
Родитель
Сommit
6abe1fff9e
6 измененных файлов с 7 добавлено и 4 удалено
  1. 1 1
      env/.env.development
  2. 1 1
      env/.env.production
  3. 1 1
      env/.env.test
  4. 2 0
      src/env.d.ts
  5. 1 1
      src/utils/http.ts
  6. 1 0
      tsconfig.json

+ 1 - 1
env/.env.development

@@ -1,6 +1,6 @@
 # 变量必须以 VITE_ 为前缀才能暴露给外部读取
 # 变量必须以 VITE_ 为前缀才能暴露给外部读取
 NODE_ENV = 'development'
 NODE_ENV = 'development'
-VITE_API_SERVER = 'http://localhost:4000'
+VITE_SERVER_BASEURL = 'http://localhost:4000'
 
 
 # 是否去除console 和 debugger
 # 是否去除console 和 debugger
 VITE_DELETE_CONSOLE = false
 VITE_DELETE_CONSOLE = false

+ 1 - 1
env/.env.production

@@ -1,6 +1,6 @@
 # 变量必须以 VITE_ 为前缀才能暴露给外部读取
 # 变量必须以 VITE_ 为前缀才能暴露给外部读取
 NODE_ENV = 'development'
 NODE_ENV = 'development'
-VITE_API_SERVER = 'https://xxx.com'
+VITE_SERVER_BASEURL = 'https://xxx.com'
 
 
 # 是否去除console 和 debugger
 # 是否去除console 和 debugger
 VITE_DELETE_CONSOLE = true
 VITE_DELETE_CONSOLE = true

+ 1 - 1
env/.env.test

@@ -1,6 +1,6 @@
 # 变量必须以 VITE_ 为前缀才能暴露给外部读取
 # 变量必须以 VITE_ 为前缀才能暴露给外部读取
 NODE_ENV = 'development'
 NODE_ENV = 'development'
-VITE_API_SERVER = 'https://xxx.com'
+VITE_SERVER_BASEURL = 'https://xxx.com'
 
 
 # 是否去除console 和 debugger
 # 是否去除console 和 debugger
 VITE_DELETE_CONSOLE = false
 VITE_DELETE_CONSOLE = false

+ 2 - 0
src/env.d.ts

@@ -11,6 +11,8 @@ declare module '*.vue' {
 interface ImportMetaEnv {
 interface ImportMetaEnv {
   readonly VITE_APP_TITLE: string
   readonly VITE_APP_TITLE: string
   readonly VITE_SERVER_PORT: string
   readonly VITE_SERVER_PORT: string
+  readonly VITE_SERVER_BASEURL: string
+  readonly VITE_DELETE_CONSOLE: string
   // 更多环境变量...
   // 更多环境变量...
 }
 }
 
 

+ 1 - 1
src/utils/http.ts

@@ -10,7 +10,7 @@ type Data<T> = {
 }
 }
 
 
 // 请求基地址
 // 请求基地址
-const baseURL = 'http://localhost:5565/api'
+const baseURL = import.meta.env.VITE_SERVER_BASEURL
 
 
 // 拦截器配置
 // 拦截器配置
 const httpInterceptor = {
 const httpInterceptor = {

+ 1 - 0
tsconfig.json

@@ -1,5 +1,6 @@
 {
 {
   "compilerOptions": {
   "compilerOptions": {
+    "module": "ESNext",
     "sourceMap": true,
     "sourceMap": true,
     "baseUrl": ".",
     "baseUrl": ".",
     "paths": {
     "paths": {