feat: massive front-end overhaul and initial github release
This commit is contained in:
parent
a2b40e38bf
commit
d5a0e70580
303 changed files with 19840 additions and 676 deletions
38
src/bun/api/clients.ts
Normal file
38
src/bun/api/clients.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { config } from "./settings";
|
||||
import Elysia from "elysia";
|
||||
|
||||
export const romm = new Elysia({ prefix: "/romm" })
|
||||
.all("/*", async ({ request, params, set }) =>
|
||||
{
|
||||
if (!config.has('rommAddress') && !config.get('rommAddress'))
|
||||
{
|
||||
return new Response("Romm Address Not Found", { status: 404 });
|
||||
}
|
||||
|
||||
const rommUrl = new URL(config.get('rommAddress')!);
|
||||
const url = new URL(request.url);
|
||||
url.pathname = url.pathname.replace(/^\/api\/romm/, '');
|
||||
url.host = rommUrl.host;
|
||||
url.port = rommUrl.port;
|
||||
url.protocol = rommUrl.protocol;
|
||||
|
||||
// Forward headers (optional: remove host if needed)
|
||||
const headers = new Headers(request.headers);
|
||||
headers.delete('host');
|
||||
headers.set("accept-encoding", "identity");
|
||||
|
||||
const rommResponse = await fetch(url, {
|
||||
method: request.method,
|
||||
headers,
|
||||
body: await request.arrayBuffer(),
|
||||
redirect: 'manual', // avoid ROMM redirects
|
||||
});
|
||||
|
||||
set.status = rommResponse.status;
|
||||
rommResponse.headers.forEach((value, key) =>
|
||||
{
|
||||
set.headers[key] = value;
|
||||
});
|
||||
|
||||
return new Response(rommResponse.body, { status: rommResponse.status });
|
||||
});
|
||||
42
src/bun/api/rpc.ts
Normal file
42
src/bun/api/rpc.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import { RPC_PORT } from "../../shared/constants";
|
||||
import { settings } from "./settings";
|
||||
import { romm } from "./clients";
|
||||
import Elysia from "elysia";
|
||||
import { cors } from "@elysiajs/cors";
|
||||
import { host } from "../utils";
|
||||
|
||||
const api = new Elysia({ prefix: "/api", serve: {} })
|
||||
.use(cors())
|
||||
.use(romm)
|
||||
.use(settings);
|
||||
|
||||
export type AppType = typeof api;
|
||||
|
||||
export function RunAPIServer ()
|
||||
{
|
||||
console.log("Launching API Server on port ", RPC_PORT);
|
||||
return {
|
||||
apiServer: api.listen({
|
||||
port: RPC_PORT,
|
||||
hostname: host,
|
||||
development: process.env.NODE_ENV === 'development',
|
||||
fetch (req, server)
|
||||
{
|
||||
if (server.upgrade(req, {
|
||||
data: undefined
|
||||
}))
|
||||
{
|
||||
return;
|
||||
}
|
||||
return api.fetch(req);
|
||||
},
|
||||
websocket: {
|
||||
message (ws, message)
|
||||
{
|
||||
|
||||
|
||||
},
|
||||
}
|
||||
})
|
||||
};
|
||||
}
|
||||
29
src/bun/api/settings.ts
Normal file
29
src/bun/api/settings.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import z from "zod";
|
||||
import { SettingsSchema, SettingsType } from "../../shared/constants";
|
||||
import Conf from "conf";
|
||||
import projectPackage from '../../../package.json';
|
||||
import Elysia from "elysia";
|
||||
|
||||
export const config = new Conf<SettingsType>({
|
||||
projectName: projectPackage.name,
|
||||
projectSuffix: 'bun',
|
||||
schema: Object.fromEntries(Object.entries(SettingsSchema.shape).map(([key, schema]) => [key, schema.toJSONSchema() as any])) as any,
|
||||
defaults: SettingsSchema.parse({}),
|
||||
});
|
||||
console.log("Config Path Located At: ", config.path);
|
||||
|
||||
export const settings = new Elysia({ prefix: '/settings' })
|
||||
.get("/:id", async ({ params: { id } }) =>
|
||||
{
|
||||
const value = config.get(id);
|
||||
return { value: value };
|
||||
}, {
|
||||
params: z.object({ id: z.keyof(SettingsSchema) }),
|
||||
}).post('/:id',
|
||||
async ({ params: { id }, body: { value }, }) =>
|
||||
{
|
||||
config.set(id, value);
|
||||
}, {
|
||||
params: z.object({ id: z.keyof(SettingsSchema) }),
|
||||
body: z.object({ value: z.any() })
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue