chore: first build

This commit is contained in:
2024-08-17 04:55:01 +07:00
parent 61a07068d5
commit e1d2274bfb
37 changed files with 537 additions and 59 deletions
+2
View File
@@ -0,0 +1,2 @@
//
export const __PROD = import.meta.env.NODE_ENV === "production";
+13 -1
View File
@@ -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.");
}
+2 -1
View File
@@ -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;
+9 -4
View File
@@ -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;
};