feat: add url prefix
This commit is contained in:
@@ -2,8 +2,14 @@
|
||||
|
||||
const isProduction = process.env.NODE_ENV === 'prod';
|
||||
|
||||
// 从 window 对象获取路径前缀(由后端注入或通过 API 获取)
|
||||
const getPathPrefix = () => {
|
||||
return window.__URL_PATH_PREFIX__ || '';
|
||||
};
|
||||
|
||||
const config = {
|
||||
apiUrl: isProduction ? '' : 'http://localhost:8000',
|
||||
pathPrefix: getPathPrefix(),
|
||||
};
|
||||
|
||||
export default config;
|
||||
|
||||
+6
-1
@@ -10,8 +10,13 @@ import { toast } from "vue-sonner"
|
||||
|
||||
const ERR_NETWORK = "ERR_NETWORK";
|
||||
|
||||
// 获取路径前缀
|
||||
const getPathPrefix = () => {
|
||||
return config.pathPrefix || '';
|
||||
};
|
||||
|
||||
const request = axios.create({
|
||||
baseURL: config.apiUrl,
|
||||
baseURL: config.apiUrl + getPathPrefix(),
|
||||
timeout: 50000,
|
||||
withCredentials: true,
|
||||
});
|
||||
|
||||
+5
-4
@@ -20,7 +20,8 @@ import router from './router';
|
||||
} catch (_) {}
|
||||
})();
|
||||
|
||||
const app = createApp(App)
|
||||
app.use(router)
|
||||
app.use(pinia)
|
||||
app.mount('#app')
|
||||
const app = createApp(App);
|
||||
app.use(router);
|
||||
app.use(pinia);
|
||||
app.mount('#app');
|
||||
|
||||
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
declare global {
|
||||
interface Window {
|
||||
__URL_PATH_PREFIX__?: string;
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
Reference in New Issue
Block a user