refactor(server): removed the websocket wrapper going wiht normal ws
This commit is contained in:
2
database/migrations/0025_amusing_sugar_man.sql
Normal file
2
database/migrations/0025_amusing_sugar_man.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
DROP TABLE "apiHits" CASCADE;--> statement-breakpoint
|
||||
DROP TABLE "eom" CASCADE;
|
||||
1056
database/migrations/meta/0025_snapshot.json
Normal file
1056
database/migrations/meta/0025_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -176,6 +176,13 @@
|
||||
"when": 1742408812383,
|
||||
"tag": "0024_curved_venom",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 25,
|
||||
"version": "7",
|
||||
"when": 1742655504936,
|
||||
"tag": "0025_amusing_sugar_man",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -21,9 +21,7 @@ import loggerService from "./services/logger/loggerService.js";
|
||||
import ocpService from "./services/ocp/ocpService.js";
|
||||
import { db } from "../database/dbclient.js";
|
||||
import { settings } from "../database/schema/settings.js";
|
||||
import {count, eq} from "drizzle-orm";
|
||||
import {createNodeWebSocket} from "@hono/node-ws";
|
||||
import {streamSSE} from "hono/streaming";
|
||||
import { count } from "drizzle-orm";
|
||||
|
||||
// create the main prodlogin here
|
||||
const username = "lst_user";
|
||||
@@ -32,11 +30,13 @@ export const lstAuth = btoa(`${username}:${password}`);
|
||||
|
||||
// checking to make sure we have the settings intialized
|
||||
const serverIntialized = await db.select({ count: count() }).from(settings);
|
||||
export const installed = serverIntialized[0].count === 0 && process.env.NODE_ENV !== "development" ? false : true;
|
||||
export const installed =
|
||||
serverIntialized[0].count === 0 && process.env.NODE_ENV !== "development"
|
||||
? false
|
||||
: true;
|
||||
createLog("info", "LST", "server", `Server is installed: ${installed}`);
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
export const {injectWebSocket, upgradeWebSocket} = createNodeWebSocket({app});
|
||||
|
||||
// middle ware
|
||||
app.use("*", logger());
|
||||
@@ -73,39 +73,6 @@ app.doc("/api/ref", {
|
||||
},
|
||||
});
|
||||
|
||||
app.get(
|
||||
"/api/log",
|
||||
// upgradeWebSocket(() => {
|
||||
// return {
|
||||
// onMessage(event, ws) {
|
||||
// console.log(`Message from client: ${event.data}`);
|
||||
// ws.send("Hello from server!");
|
||||
// },
|
||||
// onClose: () => {
|
||||
// console.log("Connection closed");
|
||||
// },
|
||||
// };
|
||||
// })
|
||||
async (c) => {
|
||||
let id = 0;
|
||||
let running = true;
|
||||
return streamSSE(c, async (stream) => {
|
||||
while (running) {
|
||||
const message = `It is ${new Date().toISOString()}`;
|
||||
await stream.writeSSE({
|
||||
data: message,
|
||||
event: "time-update",
|
||||
id: String(id++),
|
||||
});
|
||||
await stream.sleep(1000);
|
||||
if (id === 5) {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
const routes = [
|
||||
scalar,
|
||||
auth,
|
||||
@@ -184,8 +151,11 @@ process.on("beforeExit", async () => {
|
||||
//await closePool();
|
||||
});
|
||||
|
||||
const port = process.env.NODE_ENV === "development" ? process.env.VITE_SERVER_PORT : process.env.PROD_PORT;
|
||||
injectWebSocket(
|
||||
const port =
|
||||
process.env.NODE_ENV === "development"
|
||||
? process.env.VITE_SERVER_PORT
|
||||
: process.env.PROD_PORT;
|
||||
|
||||
serve(
|
||||
{
|
||||
fetch: app.fetch,
|
||||
@@ -193,9 +163,13 @@ injectWebSocket(
|
||||
hostname: "0.0.0.0",
|
||||
},
|
||||
(info) => {
|
||||
createLog("info", "LST", "server", `Server is running on http://${info.address}:${info.port}`);
|
||||
createLog(
|
||||
"info",
|
||||
"LST",
|
||||
"server",
|
||||
`Server is running on http://${info.address}:${info.port}`
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
export type AppRoutes = typeof appRoutes;
|
||||
|
||||
Reference in New Issue
Block a user