add env vars for configuring onion and I2P urls
Signed-off-by: ngn <ngn@ngn.tf>
This commit is contained in:
@ -3,21 +3,44 @@ import { defineConfig } from "vite";
|
||||
import { fileURLToPath } from "url";
|
||||
import { readFileSync } from "fs";
|
||||
|
||||
function env_from(prefix, object) {
|
||||
for (const [key, value] of Object.entries(object)) {
|
||||
let type = typeof value;
|
||||
let name = prefix + "_" + key.toUpperCase();
|
||||
|
||||
switch (type) {
|
||||
case "object":
|
||||
env_from(name, value);
|
||||
break;
|
||||
|
||||
case "string":
|
||||
if (process.env[name] === undefined) process.env[name] = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const default_env = {
|
||||
REPORT_URL: "https://github.com/ngn13/website/issues",
|
||||
SOURCE_URL: "https://github.com/ngn13/website",
|
||||
APP_URL: "http://localhost:7001",
|
||||
API_URL: "http://localhost:7002",
|
||||
DOC_URL: "http://localhost:7003",
|
||||
source_url: "https://git.ngn.tf/ngn/website",
|
||||
report_url: "https://git.ngn.tf/ngn/website/issues",
|
||||
doc_url: "http://localhost:7003",
|
||||
app_url: {
|
||||
clear: "http://localhost:7001",
|
||||
onion: "",
|
||||
i2p: "",
|
||||
},
|
||||
api_url: {
|
||||
clear: "http://localhost:7002",
|
||||
onion: "",
|
||||
i2p: "",
|
||||
},
|
||||
};
|
||||
|
||||
const file = fileURLToPath(new URL("package.json", import.meta.url));
|
||||
const json = readFileSync(file, "utf8");
|
||||
const pkg = JSON.parse(json);
|
||||
const package_file = fileURLToPath(new URL("package.json", import.meta.url));
|
||||
const package_json = readFileSync(package_file, "utf8");
|
||||
const package_data = JSON.parse(package_json);
|
||||
|
||||
for (let env in default_env) {
|
||||
if (process.env["WEBSITE_" + env] === undefined) process.env["WEBSITE_" + env] = default_env[env];
|
||||
}
|
||||
env_from("WEBSITE", default_env);
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [sveltekit()],
|
||||
@ -31,6 +54,6 @@ export default defineConfig({
|
||||
strictPort: true,
|
||||
},
|
||||
define: {
|
||||
pkg: pkg,
|
||||
pkg: package_data,
|
||||
},
|
||||
});
|
||||
|
Reference in New Issue
Block a user