From 4de905972c69d0fbec1d55a8b1eed945f28ce80c Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 6 Mar 2025 15:04:13 +0700 Subject: [PATCH] ws test --- src/app.ts | 6 ++++-- src/controllers/ReportController.ts | 2 +- src/services/webSocket.ts | 6 ++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/app.ts b/src/app.ts index 8ea1260c..8c9cad7f 100644 --- a/src/app.ts +++ b/src/app.ts @@ -13,9 +13,11 @@ import { OrganizationController } from "./controllers/OrganizationController"; import logMiddleware from "./middlewares/logs"; import { CommandController } from "./controllers/CommandController"; import { ProfileSalaryController } from "./controllers/ProfileSalaryController"; +import { WebSocketServer } from "ws"; import http from "http"; -import { wss } from "../src/services/webSocket"; - +export const wss = new WebSocketServer({ noServer: true, + path: "/api/v1/org/socket", + }); async function main() { await AppDataSource.initialize(); diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index d1847536..1a575842 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -3540,7 +3540,7 @@ export class ReportController extends Controller { } const metaData = { template: "report2", reportName: "report2", data: { data } }; sendWebSocket(metaData) - // return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } }); + return new HttpSuccess(); } /** diff --git a/src/services/webSocket.ts b/src/services/webSocket.ts index ff8ee3e1..32ea70af 100644 --- a/src/services/webSocket.ts +++ b/src/services/webSocket.ts @@ -1,7 +1,5 @@ -import { WebSocket, WebSocketServer } from "ws"; -export const wss = new WebSocketServer({ noServer: true, - path: "/api/v1/org/socket", - }); +import { WebSocket } from "ws"; +import { wss } from "../app"; export async function sendWebSocket(data:any){ wss.clients.forEach((client: any) => {