chore: remove unnecessary env (#6022)

#### What type of PR is this?

/area ui
/kind cleanup
/milestone 2.16.x

#### What this PR does / why we need it:

移除 UI 项目中不必要的环境变量配置。

1. VITE_API_URL:当前 Console 不会考虑独立部署,并且在开发环境是后端 Proxy 的 Console 请求,所以此变量没有任何意义。
2. VITE_BASE_URL:无意义,当前不考虑修改。

#### Does this PR introduce a user-facing change?

```release-note
None
```
pull/6009/head v2.16.0-rc.2
Ryan Wang 2024-05-30 16:31:16 +08:00 committed by GitHub
parent 296d8c5833
commit a26b73e258
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 32 additions and 65 deletions

View File

@ -1,2 +0,0 @@
VITE_API_URL=
VITE_BASE_URL=/console/

View File

@ -1,2 +0,0 @@
VITE_API_URL=
VITE_BASE_URL=/console/

View File

@ -6,12 +6,9 @@ export function useGlobalInfoFetch() {
const { data } = useQuery<GlobalInfo>({ const { data } = useQuery<GlobalInfo>({
queryKey: ["globalinfo"], queryKey: ["globalinfo"],
queryFn: async () => { queryFn: async () => {
const { data } = await axios.get<GlobalInfo>( const { data } = await axios.get<GlobalInfo>(`/actuator/globalinfo`, {
`${import.meta.env.VITE_API_URL}/actuator/globalinfo`, withCredentials: true,
{ });
withCredentials: true,
}
);
return data; return data;
}, },

View File

@ -47,7 +47,7 @@ const handleLogout = () => {
cancelText: t("core.common.buttons.cancel"), cancelText: t("core.common.buttons.cancel"),
onConfirm: async () => { onConfirm: async () => {
try { try {
await axios.post(`${import.meta.env.VITE_API_URL}/logout`, undefined, { await axios.post(`/logout`, undefined, {
withCredentials: true, withCredentials: true,
}); });

View File

@ -88,9 +88,7 @@ const previewUrl = computed(() => {
if (!selectedTheme.value) { if (!selectedTheme.value) {
return "#"; return "#";
} }
return `${import.meta.env.VITE_API_URL}/?preview-theme=${ return `/?preview-theme=${selectedTheme.value.metadata.name}`;
selectedTheme.value.metadata.name
}`;
}); });
const modalTitle = computed(() => { const modalTitle = computed(() => {

View File

@ -31,12 +31,9 @@ const { currentUserHasPermission } = usePermission();
const { data: info } = useQuery<Info>({ const { data: info } = useQuery<Info>({
queryKey: ["system-info"], queryKey: ["system-info"],
queryFn: async () => { queryFn: async () => {
const { data } = await axios.get<Info>( const { data } = await axios.get<Info>(`/actuator/info`, {
`${import.meta.env.VITE_API_URL}/actuator/info`, withCredentials: true,
{ });
withCredentials: true,
}
);
return data; return data;
}, },
retry: 0, retry: 0,
@ -45,12 +42,9 @@ const { data: info } = useQuery<Info>({
const { data: globalInfo } = useQuery<GlobalInfo>({ const { data: globalInfo } = useQuery<GlobalInfo>({
queryKey: ["system-global-info"], queryKey: ["system-global-info"],
queryFn: async () => { queryFn: async () => {
const { data } = await axios.get<GlobalInfo>( const { data } = await axios.get<GlobalInfo>(`/actuator/globalinfo`, {
`${import.meta.env.VITE_API_URL}/actuator/globalinfo`, withCredentials: true,
{ });
withCredentials: true,
}
);
return data; return data;
}, },
retry: 0, retry: 0,
@ -59,12 +53,9 @@ const { data: globalInfo } = useQuery<GlobalInfo>({
const { data: startup } = useQuery<Startup>({ const { data: startup } = useQuery<Startup>({
queryKey: ["system-startup-info"], queryKey: ["system-startup-info"],
queryFn: async () => { queryFn: async () => {
const { data } = await axios.get<Startup>( const { data } = await axios.get<Startup>(`/actuator/startup`, {
`${import.meta.env.VITE_API_URL}/actuator/startup`, withCredentials: true,
{ });
withCredentials: true,
}
);
return data; return data;
}, },
retry: 0, retry: 0,
@ -201,7 +192,7 @@ const handleCopy = () => {
const handleDownloadLogfile = () => { const handleDownloadLogfile = () => {
axios axios
.get(`${import.meta.env.VITE_API_URL}/actuator/logfile`) .get(`/actuator/logfile`)
.then((response) => { .then((response) => {
const blob = new Blob([response.data]); const blob = new Blob([response.data]);
const downloadElement = document.createElement("a"); const downloadElement = document.createElement("a");

View File

@ -19,9 +19,7 @@ export async function setupPluginModules(app: App) {
const pluginModuleStore = usePluginModuleStore(); const pluginModuleStore = usePluginModuleStore();
try { try {
const { load } = useScriptTag( const { load } = useScriptTag(
`${ `/apis/api.console.halo.run/v1alpha1/plugins/-/bundle.js?t=${Date.now()}`
import.meta.env.VITE_API_URL
}/apis/api.console.halo.run/v1alpha1/plugins/-/bundle.js?t=${Date.now()}`
); );
await load(); await load();
@ -43,9 +41,7 @@ export async function setupPluginModules(app: App) {
try { try {
await loadStyle( await loadStyle(
`${ `/apis/api.console.halo.run/v1alpha1/plugins/-/bundle.css?t=${Date.now()}`
import.meta.env.VITE_API_URL
}/apis/api.console.halo.run/v1alpha1/plugins/-/bundle.css?t=${Date.now()}`
); );
} catch (e) { } catch (e) {
const message = i18n.global.t("core.plugin.loader.toast.style_load_failed"); const message = i18n.global.t("core.plugin.loader.toast.style_load_failed");

View File

@ -57,7 +57,7 @@ async function handleLogin(data: {
encrypt.setPublicKey(publicKey.base64Format as string); encrypt.setPublicKey(publicKey.base64Format as string);
await axios.post( await axios.post(
`${import.meta.env.VITE_API_URL}/login?remember-me=${data.rememberMe}`, `/login?remember-me=${data.rememberMe}`,
qs.stringify({ qs.stringify({
_csrf: _csrf.value, _csrf: _csrf.value,
username: data.username, username: data.username,

View File

@ -20,7 +20,7 @@ async function onSubmit({ code }: { code: string }) {
return; return;
} }
await axios.post( await axios.post(
`${import.meta.env.VITE_API_URL}/login/2fa/totp`, `/login/2fa/totp`,
qs.stringify({ qs.stringify({
code, code,
_csrf, _csrf,

View File

@ -66,7 +66,7 @@ const uppy = computed(() => {
autoProceed: props.autoProceed, autoProceed: props.autoProceed,
}) })
.use(XHRUpload, { .use(XHRUpload, {
endpoint: `${import.meta.env.VITE_API_URL}${props.endpoint}`, endpoint: `${props.endpoint}`,
allowedMetaFields: props.allowedMetaFields, allowedMetaFields: props.allowedMetaFields,
withCredentials: true, withCredentials: true,
formData: true, formData: true,

View File

@ -7,12 +7,9 @@ export const useGlobalInfoStore = defineStore("global-info", () => {
const globalInfo = ref<GlobalInfo>(); const globalInfo = ref<GlobalInfo>();
async function fetchGlobalInfo() { async function fetchGlobalInfo() {
const { data } = await axios.get<GlobalInfo>( const { data } = await axios.get<GlobalInfo>(`/actuator/globalinfo`, {
`${import.meta.env.VITE_API_URL}/actuator/globalinfo`, withCredentials: true,
{ });
withCredentials: true,
}
);
globalInfo.value = data; globalInfo.value = data;
} }

View File

@ -57,7 +57,7 @@ import { useUserStore } from "@/stores/user";
import { Toast } from "@halo-dev/components"; import { Toast } from "@halo-dev/components";
import { i18n } from "@/locales"; import { i18n } from "@/locales";
const baseURL = import.meta.env.VITE_API_URL; const baseURL = "/";
const axiosInstance = axios.create({ const axiosInstance = axios.create({
baseURL, baseURL,

View File

@ -43,7 +43,7 @@ const handleLogout = () => {
cancelText: t("core.common.buttons.cancel"), cancelText: t("core.common.buttons.cancel"),
onConfirm: async () => { onConfirm: async () => {
try { try {
await axios.post(`${import.meta.env.VITE_API_URL}/logout`, undefined, { await axios.post(`/logout`, undefined, {
withCredentials: true, withCredentials: true,
}); });

View File

@ -45,12 +45,9 @@ const handleUnbindAuth = (authProvider: ListedAuthProvider) => {
confirmText: t("core.common.buttons.confirm"), confirmText: t("core.common.buttons.confirm"),
cancelText: t("core.common.buttons.cancel"), cancelText: t("core.common.buttons.cancel"),
onConfirm: async () => { onConfirm: async () => {
await axios.put( await axios.put(`${authProvider.unbindingUrl}`, {
`${import.meta.env.VITE_API_URL}${authProvider.unbindingUrl}`, withCredentials: true,
{ });
withCredentials: true,
}
);
window.location.reload(); window.location.reload();
}, },

View File

@ -19,9 +19,7 @@ export async function setupPluginModules(app: App) {
const pluginModuleStore = usePluginModuleStore(); const pluginModuleStore = usePluginModuleStore();
try { try {
const { load } = useScriptTag( const { load } = useScriptTag(
`${ `/apis/api.console.halo.run/v1alpha1/plugins/-/bundle.js?t=${Date.now()}`
import.meta.env.VITE_API_URL
}/apis/api.console.halo.run/v1alpha1/plugins/-/bundle.js?t=${Date.now()}`
); );
await load(); await load();
@ -43,9 +41,7 @@ export async function setupPluginModules(app: App) {
try { try {
await loadStyle( await loadStyle(
`${ `/apis/api.console.halo.run/v1alpha1/plugins/-/bundle.css?t=${Date.now()}`
import.meta.env.VITE_API_URL
}/apis/api.console.halo.run/v1alpha1/plugins/-/bundle.css?t=${Date.now()}`
); );
} catch (e) { } catch (e) {
const message = i18n.global.t("core.plugin.loader.toast.style_load_failed"); const message = i18n.global.t("core.plugin.loader.toast.style_load_failed");

View File

@ -1,12 +1,11 @@
import path from "path"; import path from "path";
import { loadEnv, Plugin } from "vite"; import { Plugin } from "vite";
import VueI18nPlugin from "@intlify/unplugin-vue-i18n/vite"; import VueI18nPlugin from "@intlify/unplugin-vue-i18n/vite";
import { createViteConfig } from "./src/vite/config-builder"; import { createViteConfig } from "./src/vite/config-builder";
export default ({ mode }: { mode: string }) => { export default ({ mode }: { mode: string }) => {
const env = loadEnv(mode, process.cwd(), "");
return createViteConfig({ return createViteConfig({
base: env.VITE_BASE_URL, base: "/console/",
entryFile: "/console-src/main.ts", entryFile: "/console-src/main.ts",
port: 3000, port: 3000,
outDir: path.resolve("build/dist/console"), outDir: path.resolve("build/dist/console"),