fix: 🐛 API代理

This commit is contained in:
“chenhuachun”
2026-04-22 23:53:52 +08:00
parent 25cf3427ea
commit 8c596c6911
6 changed files with 15 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
export default {
'/api': {
target: 'http://localhost:3000',
target: 'http://localhost:8000',
changeOrigin: true,
ws: true
}

View File

@@ -4,7 +4,7 @@ import router from './router';
import { AdapterPlugin, IconsPlugin } from '@vtj/web';
// import ElementPlus from 'element-plus';
import '@/style/index.scss';
import './mock';
// import './mock';
const app = createApp(App);
app.use(router);

View File

@@ -4,6 +4,7 @@
<ElButton @click="execApi1">Test api1</ElButton>
<ElButton @click="doRequest">Test api2</ElButton>
<ElButton @click="doRequest3">Test api3</ElButton>
<ElButton @click="doRequest4">Test api4</ElButton>
</div>
</template>
<script lang="ts" setup>
@@ -79,6 +80,12 @@
});
};
const doRequest4 = () => {
request({
url: 'https://app.vtj.pro/api/proxy'
});
};
// const url = '/api/test/user/${id}';
// const url = '/api/scm/auth/scm/scmPurchaseApplyH/waitList.do';
// const url = '/mock/api/:id.json';

View File

@@ -2,11 +2,8 @@
"compilerOptions": {
"composite": true,
"module": "ESNext",
"moduleResolution": "Node",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": [
"vite.config.ts",
"proxy.config.ts"
]
}
"include": ["vite.config.ts", "proxy.config.ts"]
}

View File

@@ -73,7 +73,7 @@ function creator() {
],
plugins: [
createDevTools({
hm: null,
hm: '',
link: false,
copy: false,
devMode: true,

View File

@@ -28,6 +28,7 @@ const DATA_METHODS = ['put', 'post', 'patch'];
const LOCAL_REQUEST_ID = 'Local-Request-Id';
const LOADING_DELAY = 100;
const ERROR_DELAY = 300;
const PROXY_PATH = '/api/proxy';
export interface IRequestSkipWarn {
// 处理程序
@@ -337,7 +338,7 @@ export class Request {
headers
};
}
const path = settings.proxyPath || '/api/open/proxy/v1';
const path = settings.proxyPath || PROXY_PATH;
const { protocol, host } = location || {};
const target = isUrl(url) ? url : `${protocol}//${host}${url}`;
headers.Target = target;