环境变量

This commit is contained in:
2025-05-09 08:15:00 +08:00
parent dbd9486d8e
commit 69a62ece22
10 changed files with 38 additions and 5 deletions

4
.env Normal file
View File

@@ -0,0 +1,4 @@
VITE_MAXKB_URL=https://maxkb.xuyue.cc/api/application/embed?protocol=https&host=maxkb.xuyue.cc&token=1b7cd529423b3f36
VITE_OJ_URL=https://ojtest.xuyue.cc
VITE_CODE_URL=https://code.xuyue.cc
VITE_JUDGE0_URL=https://judge0api.xuyue.cc

4
.env.production Normal file
View File

@@ -0,0 +1,4 @@
VITE_MAXKB_URL=https://maxkb.xuyue.cc/api/application/embed?protocol=https&host=maxkb.xuyue.cc&token=1b7cd529423b3f36
VITE_OJ_URL=https://oj.xuyue.cc
VITE_CODE_URL=https://code.xuyue.cc
VITE_JUDGE0_URL=https://judge0api.xuyue.cc

5
.env.staging Normal file
View File

@@ -0,0 +1,5 @@
VITE_MAXKB_URL=https://maxkb.xuyue.cc/api/application/embed?protocol=https&host=maxkb.xuyue.cc&token=1b7cd529423b3f36
VITE_OJ_URL=http://10.13.114.214:81
VITE_CODE_URL=http://10.13.114.214:82
VITE_JUDGE0_URL=http://10.13.114.214:8082
VITE_ICONIFY_URL=http://10.13.114.214:8098

View File

@@ -12,7 +12,7 @@
<script <script
async async
defer defer
src="https://maxkb.xuyue.cc/api/application/embed?protocol=https&host=maxkb.xuyue.cc&token=1b7cd529423b3f36" src="%VITE_MAXKB_URL%"
></script> ></script>
</head> </head>
<body> <body>

View File

@@ -5,6 +5,7 @@
"scripts": { "scripts": {
"start": "vite", "start": "vite",
"build": "vue-tsc && vite build", "build": "vue-tsc && vite build",
"build:staging": "vue-tsc && vite build --mode=staging",
"preview": "vite preview", "preview": "vite preview",
"fmt": "prettier --write src *.ts" "fmt": "prettier --write src *.ts"
}, },

View File

@@ -1,3 +1,4 @@
import { addAPIProvider } from "@iconify/vue"
import { createPinia } from "pinia" import { createPinia } from "pinia"
import { createRouter, createWebHistory } from "vue-router" import { createRouter, createWebHistory } from "vue-router"
@@ -32,3 +33,9 @@ const app = createApp(App)
app.use(router) app.use(router)
app.use(pinia) app.use(pinia)
app.mount("#app") app.mount("#app")
if (!!import.meta.env.VITE_ICONIFY_URL) {
addAPIProvider("", {
resources: [import.meta.env.VITE_ICONIFY_URL],
})
}

View File

@@ -92,7 +92,7 @@ async function select(key: string) {
copy() copy()
break break
case "test": case "test":
window.open("https://code.xuyue.cc", "_blank") window.open(import.meta.env.VITE_CODE_URL, "_blank")
break break
} }
} }

View File

@@ -2,7 +2,7 @@ import axios from "axios"
import { decode, encode } from "./functions" import { decode, encode } from "./functions"
import { Code } from "./types" import { Code } from "./types"
const http = axios.create({ baseURL: `https://judge0api.xuyue.cc` }) const http = axios.create({ baseURL: import.meta.env.VITE_JUDGE0_URL })
export async function createTestSubmission(code: Code, input: string) { export async function createTestSubmission(code: Code, input: string) {
const encodedCode = encode(code.value) const encodedCode = encode(code.value)

12
src/vite-env.d.ts vendored
View File

@@ -1 +1,13 @@
/// <reference types="vite/client" /> /// <reference types="vite/client" />
interface ImportMetaEnv {
readonly VITE_MAXKB_URL: string
readonly VITE_OJ_URL: string
readonly VITE_CODE_URL: string
readonly VITE_JUDGE0_URL: string
readonly VITE_ICONIFY_URL: string
}
interface ImportMeta {
readonly env: ImportMetaEnv
}

View File

@@ -7,8 +7,8 @@ import Components from "unplugin-vue-components/vite"
import Markdown from "unplugin-vue-markdown/vite" import Markdown from "unplugin-vue-markdown/vite"
import { defineConfig } from "vite" import { defineConfig } from "vite"
const dev = process.env.NODE_ENV === "development" const url = process.env.VITE_OJ_URL
const url = dev ? "https://ojtest.xuyue.cc" : "https://oj.xuyue.cc"
const proxyConfig = { const proxyConfig = {
target: url, target: url,
changeOrigin: true, changeOrigin: true,