feat(lst): intial scafolding for the new system

This commit is contained in:
2025-02-16 19:07:03 -06:00
parent 5c5bce024c
commit 2e0253636e
34 changed files with 679 additions and 29 deletions

14
apps/server/index.ts Normal file
View File

@@ -0,0 +1,14 @@
import app from "./src/app";
const port = process.env.SERVER_PORT || 4000;
Bun.serve({
port,
fetch: app.fetch,
hostname: "0.0.0.0",
});
// await Bun.build({
// entrypoints: ["./index.js"],
// outdir: "../../dist/server",
// });
console.log(`server is running on port ${port}`);

13
apps/server/package.json Normal file
View File

@@ -0,0 +1,13 @@
{
"name": "lstv2-server",
"version": "1.0.0",
"description": "",
"private": true,
"scripts": {
"dev": "bun --watch index.ts",
"build": "bun build ./index.ts"
},
"devDependencies": {
"typescript": "^5.7.3"
}
}

27
apps/server/src/app.ts Normal file
View File

@@ -0,0 +1,27 @@
import { Hono } from "hono";
import { serveStatic } from "hono/bun";
import { logger } from "hono/logger";
import { ocmeService } from "./services/ocmeServer";
//import { expensesRoute } from "./routes/expenses";
const app = new Hono();
app.use("*", logger());
// as we dont want to change ocme again well use a proxy to this
app.all("/ocme/*", async (c) => {
return ocmeService(c);
});
app.get("/test", (c) => {
return c.json({ success: true, message: "hello from bun" });
});
//const apiRoute = app.basePath("/api").route("/expenses", expensesRoute);
app.get("*", serveStatic({ root: "../frontend/dist" }));
app.get("*", serveStatic({ path: "../frontend/dist/index.html" }));
export default app;
//export type ApiRoute = typeof apiRoute;

View File

@@ -0,0 +1,23 @@
import { Context } from "hono";
export const ocmeService = async (c: Context) => {
const url = new URL(c.req.url);
const ocmeUrl = `http://localhost:${
process.env.OCME_PORT
}${url.pathname.replace("/ocme", "")}`;
console.log(ocmeUrl);
const ocmeResponse = await fetch(ocmeUrl, {
method: c.req.method,
headers: c.req.raw.headers,
body:
c.req.method !== "GET" && c.req.method !== "HEAD"
? await c.req.text()
: undefined,
});
return new Response(ocmeResponse.body, {
status: ocmeResponse.status,
headers: ocmeResponse.headers,
});
};

View File

@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src", "index.ts"]
}