mirror of
https://github.com/khairul169/garage-webui.git
synced 2026-09-15 00:43:21 +07:00
chore: first build
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
//
|
||||
export const __PROD = import.meta.env.NODE_ENV === "production";
|
||||
+13
-1
@@ -1,4 +1,16 @@
|
||||
import type { Config } from "../types/garage";
|
||||
import { readTomlFile } from "./utils";
|
||||
|
||||
export const config = readTomlFile<Config>(process.env.CONFIG_PATH);
|
||||
const CONFIG_PATH = process.env.CONFIG_PATH || "/etc/garage.toml";
|
||||
|
||||
export const config = await readTomlFile<Config>(CONFIG_PATH);
|
||||
|
||||
if (!config?.rpc_public_addr) {
|
||||
throw new Error(
|
||||
"Cannot load garage config! Missing `rpc_public_addr` in config file."
|
||||
);
|
||||
}
|
||||
|
||||
if (!config?.admin?.admin_token) {
|
||||
throw new Error("Missing `admin.admin_token` in config.");
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ import { API_ADMIN_KEY, API_BASE_URL } from "./api";
|
||||
|
||||
export const proxyApi = async (c: Context) => {
|
||||
const url = new URL(c.req.url);
|
||||
const reqUrl = new URL(API_BASE_URL + url.pathname + url.search);
|
||||
const pathname = url.pathname.replace(/\/api\//, "/");
|
||||
const reqUrl = new URL(API_BASE_URL + pathname + url.search);
|
||||
|
||||
try {
|
||||
const headers = c.req.raw.headers;
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
import fs from "node:fs";
|
||||
import toml from "toml";
|
||||
|
||||
export const readTomlFile = <T = any>(path?: string | null) => {
|
||||
if (!path || !fs.existsSync(path)) {
|
||||
export const readTomlFile = async <T = any>(path?: string | null) => {
|
||||
if (!path) {
|
||||
return undefined;
|
||||
}
|
||||
return toml.parse(fs.readFileSync(path, "utf8")) as T;
|
||||
|
||||
const file = Bun.file(path);
|
||||
if (!(await file.exists())) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return toml.parse(await file.text()) as T;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user