refactor(env): 修改环境变量并调整请求前缀
- 移除 .env 文件中 VITE_APP_BASEURL 的尾部斜杠- 在 request.js 中添加 /api 前缀到 baseURL - 注释掉多余的条件判断代码- 优化响应拦截器中的状态码判断逻辑
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
# .env.development
|
# .env.development
|
||||||
VITE_APP_BASEURL=https://yls-api-uat.dctest.digitalyili.com/
|
VITE_APP_BASEURL=https://yls-api-uat.dctest.digitalyili.com
|
||||||
VITE_APP_ENV=development
|
VITE_APP_ENV=development
|
||||||
VITE_APP_CURRENTMODE=dev
|
VITE_APP_CURRENTMODE=dev
|
||||||
VITE_APP_BASEOSS=https://diaoyan-files.automark.cc
|
VITE_APP_BASEOSS=https://diaoyan-files.automark.cc
|
||||||
|
|||||||
2
.env.uat
2
.env.uat
@@ -1,5 +1,5 @@
|
|||||||
# .env.development
|
# .env.development
|
||||||
VITE_APP_BASEURL=https://yls-api-uat.dctest.digitalyili.com/
|
VITE_APP_BASEURL=https://yls-api-uat.dctest.digitalyili.com
|
||||||
VITE_APP_ENV=uat
|
VITE_APP_ENV=uat
|
||||||
VITE_APP_CURRENTMODE=uat
|
VITE_APP_CURRENTMODE=uat
|
||||||
VITE_APP_BASEOSS=https://diaoyan-files.automark.cc
|
VITE_APP_BASEOSS=https://diaoyan-files.automark.cc
|
||||||
|
|||||||
@@ -7,13 +7,12 @@ import * as config from '@/config.js';
|
|||||||
// import {proxyUrl} from config.default
|
// import {proxyUrl} from config.default
|
||||||
// const NODE_ENV = import.meta.env.VITE_APP_ENV;
|
// const NODE_ENV = import.meta.env.VITE_APP_ENV;
|
||||||
const baseURL = config.default.proxyUrl;
|
const baseURL = config.default.proxyUrl;
|
||||||
|
|
||||||
// axios.defaults.withCredentials = true;
|
// axios.defaults.withCredentials = true;
|
||||||
|
|
||||||
// create an axios instance
|
// create an axios instance
|
||||||
const service = axios.create({
|
const service = axios.create({
|
||||||
// url = base url + request url
|
// url = base url + request url
|
||||||
baseURL: `${baseURL}`,
|
baseURL: `${baseURL}/api`,
|
||||||
// withCredentials: true, // send cookies when cross-domain requests
|
// withCredentials: true, // send cookies when cross-domain requests
|
||||||
// request timeout
|
// request timeout
|
||||||
timeout: 30000
|
timeout: 30000
|
||||||
@@ -26,9 +25,10 @@ service.interceptors.request.use(
|
|||||||
config.headers.Accept = 'application/json';
|
config.headers.Accept = 'application/json';
|
||||||
}
|
}
|
||||||
config.headers.Authorization = `${localStorage.getItem('plantToken')}`;
|
config.headers.Authorization = `${localStorage.getItem('plantToken')}`;
|
||||||
if (!config.headers.remoteIp) {
|
|
||||||
config.baseURL += '/api';
|
// if (!config.headers.remoteIp) {
|
||||||
}
|
// config.baseURL += '/api';
|
||||||
|
// }
|
||||||
delete config.headers.host;
|
delete config.headers.host;
|
||||||
config.headers.remoteIp = localStorage.getItem('plantIp') || '127.0.0.1';
|
config.headers.remoteIp = localStorage.getItem('plantIp') || '127.0.0.1';
|
||||||
// if (store.state.common.token) {
|
// if (store.state.common.token) {
|
||||||
@@ -44,10 +44,10 @@ service.interceptors.request.use(
|
|||||||
service.interceptors.response.use(
|
service.interceptors.response.use(
|
||||||
(response) => {
|
(response) => {
|
||||||
if (
|
if (
|
||||||
response.status === 200
|
response.status === 200 ||
|
||||||
|| response.status === 201
|
response.status === 201 ||
|
||||||
|| response.status === 202
|
response.status === 202 ||
|
||||||
|| response.status === 204
|
response.status === 204
|
||||||
) {
|
) {
|
||||||
if (response.config.method === 'put') {
|
if (response.config.method === 'put') {
|
||||||
// message.success('保存中...');
|
// message.success('保存中...');
|
||||||
|
|||||||
Reference in New Issue
Block a user