test(streaming): more streaming test
This commit is contained in:
@@ -22,6 +22,8 @@ import ocpService from "./services/ocp/ocpService.js";
|
|||||||
import {db} from "../database/dbclient.js";
|
import {db} from "../database/dbclient.js";
|
||||||
import {settings} from "../database/schema/settings.js";
|
import {settings} from "../database/schema/settings.js";
|
||||||
import {count, eq} from "drizzle-orm";
|
import {count, eq} from "drizzle-orm";
|
||||||
|
import {createNodeWebSocket} from "@hono/node-ws";
|
||||||
|
import {streamSSE} from "hono/streaming";
|
||||||
|
|
||||||
// create the main prodlogin here
|
// create the main prodlogin here
|
||||||
const username = "lst_user";
|
const username = "lst_user";
|
||||||
@@ -34,6 +36,7 @@ export const installed = serverIntialized[0].count === 0 && process.env.NODE_ENV
|
|||||||
createLog("info", "LST", "server", `Server is installed: ${installed}`);
|
createLog("info", "LST", "server", `Server is installed: ${installed}`);
|
||||||
|
|
||||||
const app = new OpenAPIHono({strict: false});
|
const app = new OpenAPIHono({strict: false});
|
||||||
|
export const {injectWebSocket, upgradeWebSocket} = createNodeWebSocket({app});
|
||||||
|
|
||||||
// middle ware
|
// middle ware
|
||||||
app.use("*", logger());
|
app.use("*", logger());
|
||||||
@@ -70,6 +73,39 @@ 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 = [
|
const routes = [
|
||||||
scalar,
|
scalar,
|
||||||
auth,
|
auth,
|
||||||
@@ -149,15 +185,17 @@ process.on("beforeExit", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const port = process.env.NODE_ENV === "development" ? process.env.VITE_SERVER_PORT : process.env.PROD_PORT;
|
const port = process.env.NODE_ENV === "development" ? process.env.VITE_SERVER_PORT : process.env.PROD_PORT;
|
||||||
serve(
|
injectWebSocket(
|
||||||
{
|
serve(
|
||||||
fetch: app.fetch,
|
{
|
||||||
port: Number(port),
|
fetch: app.fetch,
|
||||||
hostname: "0.0.0.0",
|
port: Number(port),
|
||||||
},
|
hostname: "0.0.0.0",
|
||||||
(info) => {
|
},
|
||||||
createLog("info", "LST", "server", `Server is running on http://${info.address}:${info.port}`);
|
(info) => {
|
||||||
}
|
createLog("info", "LST", "server", `Server is running on http://${info.address}:${info.port}`);
|
||||||
|
}
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
export type AppRoutes = typeof appRoutes;
|
export type AppRoutes = typeof appRoutes;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"servers": [
|
"servers": [
|
||||||
{
|
{
|
||||||
"sName": "test",
|
"sName": "Test",
|
||||||
"serverDNS": "usmcd1vms036",
|
"serverDNS": "usmcd1vms036",
|
||||||
"plantToken": "test3",
|
"plantToken": "test3",
|
||||||
"idAdress": "10.193.0.56",
|
"idAdress": "10.193.0.56",
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
"contactPhone": "6366970253",
|
"contactPhone": "6366970253",
|
||||||
"customerTiAcc": "ALPL01BETHINT",
|
"customerTiAcc": "ALPL01BETHINT",
|
||||||
"lstServerPort": "4000",
|
"lstServerPort": "4000",
|
||||||
"active": false,
|
"active": true,
|
||||||
"serverLoc": "E:\\LST\\lstv2",
|
"serverLoc": "E:\\LST\\lstv2",
|
||||||
"oldVersion": "E:\\LST\\lst_backend",
|
"oldVersion": "E:\\LST\\lst_backend",
|
||||||
"shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]",
|
"shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]",
|
||||||
|
|||||||
Reference in New Issue
Block a user