Add Add multiple environments
This commit is contained in:
2
.env.development
Normal file
2
.env.development
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
VITE_API_URL=http://localhost:8080
|
||||||
|
VITE_API_TOKEN_URL=${VITE_API_URL}/token
|
||||||
2
.env.production
Normal file
2
.env.production
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
VITE_API_URL=http://api.fatweb.top
|
||||||
|
VITE_API_TOKEN_URL=${VITE_API_URL}/token
|
||||||
3
.env.testing
Normal file
3
.env.testing
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
NODE_ENV=development
|
||||||
|
VITE_API_URL=http://api-test.fatweb.top
|
||||||
|
VITE_API_TOKEN_URL=${VITE_API_URL}/token
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"dev-host": "vite --host 0.0.0.0",
|
"dev-host": "vite --host 0.0.0.0",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
|
"build-test": "vite build --mode testing",
|
||||||
"clean": "rimraf dist .eslintrc-auto-import.json auto-imports.d.ts",
|
"clean": "rimraf dist .eslintrc-auto-import.json auto-imports.d.ts",
|
||||||
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
||||||
"format": "prettier --write src/",
|
"format": "prettier --write src/",
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
import { message } from 'antd'
|
import { message } from 'antd'
|
||||||
|
|
||||||
const service: AxiosInstance = axios.create({
|
const service: AxiosInstance = axios.create({
|
||||||
baseURL: 'http://localhost:8181',
|
baseURL: import.meta.env.VITE_API_URL,
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
withCredentials: false
|
withCredentials: false
|
||||||
})
|
})
|
||||||
@@ -44,7 +44,7 @@ service.interceptors.request.use(
|
|||||||
jwt.exp * 1000 - new Date().getTime() > 0
|
jwt.exp * 1000 - new Date().getTime() > 0
|
||||||
) {
|
) {
|
||||||
await axios
|
await axios
|
||||||
.get('http://localhost:8181/token', {
|
.get(import.meta.env.VITE_API_TOKEN_URL, {
|
||||||
headers: { token }
|
headers: { token }
|
||||||
})
|
})
|
||||||
.then((value: AxiosResponse<_Response<Token>>) => {
|
.then((value: AxiosResponse<_Response<Token>>) => {
|
||||||
|
|||||||
9
src/vite-env.d.ts
vendored
9
src/vite-env.d.ts
vendored
@@ -1,5 +1,14 @@
|
|||||||
/// <reference types="vite/client" />
|
/// <reference types="vite/client" />
|
||||||
|
|
||||||
|
interface ImportMetaEnv {
|
||||||
|
readonly VITE_API_URL: string
|
||||||
|
readonly VITE_API_TOKEN_URL: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ImportMeta {
|
||||||
|
readonly env: ImportMetaEnv
|
||||||
|
}
|
||||||
|
|
||||||
type RouteHandle = {
|
type RouteHandle = {
|
||||||
name?: string
|
name?: string
|
||||||
menu?: boolean
|
menu?: boolean
|
||||||
|
|||||||
Reference in New Issue
Block a user