feat: 配置nginx支持web路由模式
自动部署 / build (push) Has been cancelled Details

master
luoer 2023-11-08 10:03:01 +08:00
parent c8f3a52b72
commit 6de35daab1
7 changed files with 39 additions and 11 deletions

2
.env
View File

@ -19,6 +19,8 @@ VITE_HISTORY = web
VITE_HOST = 0.0.0.0
# 端口
VITE_PORT = 3020
# 代理前缀
VITE_PROXY_PREFIX = /api,/upload
# 代理地址
VITE_PROXY = http://127.0.0.1:3030/
# API文档 说明:需返回符合 OPENAPI 规范的json内容

View File

@ -2,13 +2,14 @@ import { Service } from "./service";
import { addToastInterceptor } from "../interceptors/toast";
import { addAuthInterceptor } from "../interceptors/auth";
import { addExceptionInterceptor } from "../interceptors/exception";
import { env } from "@/config/env";
/**
* API
* @see src/api/instance/instance.ts
*/
const api = new Service({
baseURL: import.meta.env.VITE_API,
export const api = new Service({
baseURL: env.apiPrefix,
});
/**
@ -25,5 +26,3 @@ addAuthInterceptor(api.instance);
*
*/
addExceptionInterceptor(api.instance, () => api.expireHandler?.());
export { api };

25
src/config/env.ts Normal file
View File

@ -0,0 +1,25 @@
/**
*
*/
export const env = {
/**
*
*/
title: import.meta.env.VITE_TITLE,
/**
*
*/
subtitle: import.meta.env.VITE_SUBTITLE,
/**
*
*/
apiPrefix: import.meta.env.VITE_API,
/**
*
*/
historyMode: import.meta.env.VITE_HISTORY,
/**
*
*/
homePath: import.meta.env.VITE_HOME_PATH,
};

View File

@ -7,6 +7,7 @@ import { Router } from "vue-router";
import { menus } from "../menus";
import { APP_HOME_NAME } from "../routes/base";
import { APP_ROUTE_NAME, routes } from "../routes/page";
import { env } from "@/config/env";
const WHITE_LIST = ["/:all(.*)*"];
const UNSIGNIN_LIST = ["/login"];
@ -49,7 +50,7 @@ export function useAuthGuard(router: Router) {
}
if (!menuStore.menus.length) {
menuStore.setMenus(menus);
menuStore.setHome(import.meta.env.VITE_HOME_PATH);
menuStore.setHome(env.homePath);
for (const route of routes) {
router.addRoute(route);
}

View File

@ -1,3 +1,4 @@
import { env } from "@/config/env";
import { createWebHashHistory, createWebHistory } from "vue-router";
/**
@ -12,6 +13,6 @@ const HistoryMap = {
*
*/
export function historyMode() {
const mode = HistoryMap[import.meta.env.VITE_HISTORY];
const mode = HistoryMap[env.historyMode];
return mode();
}

View File

@ -1,11 +1,12 @@
import { env } from "@/config/env";
import { defineStore } from "pinia";
export const useAppStore = defineStore({
id: "app",
state: (): AppStore => ({
isDarkMode: false,
title: import.meta.env.VITE_TITLE,
subtitle: import.meta.env.VITE_SUBTITLE,
title: env.title,
subtitle: env.subtitle,
pageLoding: false,
pageTags: [],
}),
@ -70,7 +71,6 @@ export const useAppStore = defineStore({
}
},
},
persist: !import.meta.env.DEV,
});
interface AppStore {

View File

@ -99,11 +99,11 @@ export default defineConfig(({ mode }) => {
}),
/**
*
*
* @see https://github.com/btd/rollup-plugin-visualizer
*/
visualizer({
title: "产物分析 | 自动生成",
title: `构建统计 | ${env.VITE_SUBTITLE}`,
filename: ".gitea/stat.html",
}),