Browse Source

api baseURL使用环境变量

冯诚 2 years ago
parent
commit
0608d59f02
6 changed files with 10 additions and 9 deletions
  1. 3 2
      .env
  2. 1 1
      package.json
  3. 1 0
      src/env.d.ts
  4. 1 1
      src/service/repair.ts
  5. 1 2
      src/service/request.ts
  6. 3 3
      vite.config.ts

+ 3 - 2
.env

@@ -1,2 +1,3 @@
-#VITE_API_BASE=https://mockapi.eolink.com/9A5KfUCbe99f2b17204d98bfebe7a77757ce256af3e4e90
-VITE_API_BASE=http://t.ptcrepair.com.au/care
+#VITE_API_BASE=http://t.ptcrepair.com.au/care
+VITE_API_BASE=/api
+VITE_API_BASE2='/api2'

+ 1 - 1
package.json

@@ -3,7 +3,7 @@
   "version": "0.0.0",
   "scripts": {
     "dev": "vite --host",
-    "build": "vue-tsc --noEmit && vite build",
+    "build": "vite build",
     "preview": "vite preview"
   },
   "dependencies": {

+ 1 - 0
src/env.d.ts

@@ -9,6 +9,7 @@ declare module '*.vue' {
 
 interface ImportMetaEnv {
   VITE_API_BASE: string
+  VITE_API_BASE2: string
 }
 
 declare module 'nprogress'

+ 1 - 1
src/service/repair.ts

@@ -4,7 +4,7 @@ import request from './request'
 export function getShopList(params: any) {
   return request.get('/shop/list', {
     params,
-    baseURL: '/v2',
+    baseURL: import.meta.env.VITE_API_BASE2,
     cancelable: true,
   })
 }

+ 1 - 2
src/service/request.ts

@@ -18,8 +18,7 @@ interface ResponseData<T = any> {
 }
 
 const _axios = axios.create({
-  // baseURL: import.meta.env.VITE_API_BASE,
-  baseURL: '/api',
+  baseURL: import.meta.env.VITE_API_BASE,
 })
 const cancelMethods: Record<string, Canceler> = {}
 

+ 3 - 3
vite.config.ts

@@ -23,15 +23,15 @@ export default defineConfig(({ command }) => ({
   base: '/ptc/',
   server: {
     proxy: {
-      '/api': {
+      '/api/': {
         target: 'http://t.ptcrepair.com.au/care',
         changeOrigin: true,
         rewrite: path => path.replace(/^\/api/, ''),
       },
-      '/v2': {
+      '/api2/': {
         target: 'http://t.ptcrepair.com.au',
         changeOrigin: true,
-        rewrite: path => path.replace(/^\/v2/, ''),
+        rewrite: path => path.replace(/^\/api2/, ''),
       },
     },
   },