refactor(env): 修改 API基础路径并调整请求配置- 在 request.js 中将 baseURL 添加 /api 路径
- 移除 .env 文件中的末尾斜杠 - 注释掉不必要的请求头处理代码 -优化响应拦截器中的状态码判断逻辑
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
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const baseURL = config.default.proxyUrl;
|
|||||||
// 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,10 +26,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) {
|
// if (!config.headers.remoteIp) {
|
||||||
config.baseURL += '/api';
|
// 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) {
|
||||||
// config.headers['Login-Type'] = 'pc';
|
// config.headers['Login-Type'] = 'pc';
|
||||||
@@ -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