Merge branch 'adiDev' into develop
This commit is contained in:
commit
205034ab4d
2 changed files with 65 additions and 70 deletions
106
src/app.ts
106
src/app.ts
|
|
@ -12,38 +12,25 @@ import { RegisterRoutes } from "./routes";
|
||||||
import { OrganizationController } from "./controllers/OrganizationController";
|
import { OrganizationController } from "./controllers/OrganizationController";
|
||||||
import logMiddleware from "./middlewares/logs";
|
import logMiddleware from "./middlewares/logs";
|
||||||
import { CommandController } from "./controllers/CommandController";
|
import { CommandController } from "./controllers/CommandController";
|
||||||
// import { WebSocketServer } from "ws";
|
|
||||||
// import http from "http";
|
|
||||||
// export const wss = new WebSocketServer({ noServer: true });
|
|
||||||
|
|
||||||
// export const wss = new WebSocketServer({
|
import { WebSocketServer } from "ws";
|
||||||
// port: 8080,
|
import http from "http";
|
||||||
// perMessageDeflate: {
|
|
||||||
// zlibDeflateOptions: {
|
export const wss = new WebSocketServer({ noServer: true,
|
||||||
// // See zlib defaults.
|
path: "/api/vi/org/socket",
|
||||||
// chunkSize: 1024,
|
});
|
||||||
// memLevel: 7,
|
|
||||||
// level: 3
|
|
||||||
// },
|
|
||||||
// zlibInflateOptions: {
|
|
||||||
// chunkSize: 10 * 1024
|
|
||||||
// },
|
|
||||||
// // Other options settable:
|
|
||||||
// clientNoContextTakeover: true, // Defaults to negotiated value.
|
|
||||||
// serverNoContextTakeover: true, // Defaults to negotiated value.
|
|
||||||
// serverMaxWindowBits: 10, // Defaults to negotiated value.
|
|
||||||
// // Below options specified as default values.
|
|
||||||
// concurrencyLimit: 10, // Limits zlib concurrency for perf.
|
|
||||||
// threshold: 1024 // Size (in bytes) below which messages
|
|
||||||
// // should not be compressed if context takeover is disabled.
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
await AppDataSource.initialize();
|
await AppDataSource.initialize();
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
// const server = http.createServer(app);
|
// สร้างเซิร์ฟเวอร์ HTTP
|
||||||
|
const server = http.createServer(app);
|
||||||
|
|
||||||
|
// socket.instance = new Server(server, {
|
||||||
|
// cors: { origin: "*" },
|
||||||
|
// path: "/api/v1/org/socket",
|
||||||
|
// });
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
cors({
|
cors({
|
||||||
|
|
@ -94,32 +81,15 @@ async function main() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// การจัดการคำขออัปเกรดจาก HTTP เป็น WebSocket
|
|
||||||
// server.on("upgrade", (request:any, socket:any, head:any) => {
|
|
||||||
// console.log("🔹 Handling upgrade request...");
|
|
||||||
// wss.handleUpgrade(request, socket, head, (ws:any) => {
|
|
||||||
// console.log("🔹 WebSocket connection established");
|
|
||||||
// wss.emit("connection", ws, request);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
// wss.on("connection", (ws:any) => {
|
|
||||||
// console.log("✅ Client connected to WebSocket");
|
|
||||||
|
|
||||||
// ws.on("close", () => {
|
|
||||||
// console.log("❌ Client disconnected");
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
// app.listen(APP_PORT, APP_HOST, () => console.log(`Listening on: http://localhost:${APP_PORT}`));
|
// app.listen(APP_PORT, APP_HOST, () => console.log(`Listening on: http://localhost:${APP_PORT}`));
|
||||||
app.listen(
|
// app.listen(
|
||||||
APP_PORT,
|
// APP_PORT,
|
||||||
APP_HOST,
|
// APP_HOST,
|
||||||
() => (
|
// () => (
|
||||||
console.log(`[APP] Application is running on: http://localhost:${APP_PORT}`),
|
// console.log(`[APP] Application is running on: http://localhost:${APP_PORT}`),
|
||||||
console.log(`[APP] Swagger on: http://localhost:${APP_PORT}/api-docs`)
|
// console.log(`[APP] Swagger on: http://localhost:${APP_PORT}/api-docs`)
|
||||||
),
|
// ),
|
||||||
);
|
// );
|
||||||
async function runMessageQueue() {
|
async function runMessageQueue() {
|
||||||
try {
|
try {
|
||||||
await rabbitmqInit();
|
await rabbitmqInit();
|
||||||
|
|
@ -131,13 +101,37 @@ async function main() {
|
||||||
|
|
||||||
runMessageQueue();
|
runMessageQueue();
|
||||||
|
|
||||||
// สร้างเซิร์ฟเวอร์ HTTP
|
// การจัดการคำขออัปเกรดจาก HTTP เป็น WebSocket
|
||||||
|
server.on("upgrade", (request:any, socket:any, head:any) => {
|
||||||
|
console.log("🔹 Handling upgrade request...");
|
||||||
|
wss.handleUpgrade(request, socket, head, (ws:any) => {
|
||||||
|
console.log("🔹 WebSocket connection established");
|
||||||
|
wss.emit("connection", ws, request);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
wss.on("connection", (ws:any) => {
|
||||||
|
console.log("✅ Client connected to WebSocket");
|
||||||
|
|
||||||
// เริ่มเซิร์ฟเวอร์ที่พอร์ตปัจจุบัน
|
ws.on("close", () => {
|
||||||
// server.listen(8080, () => {
|
console.log("❌ Client disconnected");
|
||||||
// console.log("[APP] HTTP Server is listening on current port");
|
});
|
||||||
// });
|
|
||||||
|
ws.on("error", (error:any) => {
|
||||||
|
console.error("WebSocket error:", error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ตั้งค่า Express routes
|
||||||
|
app.get('/', (req, res) => {
|
||||||
|
res.send('Hello from Express!');
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen(APP_PORT, APP_HOST, () => {
|
||||||
|
console.log(`[APP] Application is running on: http://${APP_HOST}:${APP_PORT}`);
|
||||||
|
console.log(`[APP] Swagger on: http://${APP_HOST}:${APP_PORT}/api-docs`);
|
||||||
|
console.log("[APP] HTTP Server is listening on current port");
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,9 @@ import { Profile } from "../entities/Profile";
|
||||||
import { viewRegistryOfficer } from "../entities/view/viewRegistryOfficer";
|
import { viewRegistryOfficer } from "../entities/view/viewRegistryOfficer";
|
||||||
import { viewRegistryEmployee } from "../entities/view/viewRegistryEmployee";
|
import { viewRegistryEmployee } from "../entities/view/viewRegistryEmployee";
|
||||||
import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster";
|
import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster";
|
||||||
// import { WebSocket } from "ws";
|
|
||||||
// import { wss } from "../app";
|
import { WebSocket } from "ws";
|
||||||
|
import { wss } from "../app";
|
||||||
|
|
||||||
@Route("api/v1/org/report")
|
@Route("api/v1/org/report")
|
||||||
@Tags("Report")
|
@Tags("Report")
|
||||||
|
|
@ -3565,19 +3566,19 @@ export class ReportController extends Controller {
|
||||||
}
|
}
|
||||||
// console.log(">>",data);
|
// console.log(">>",data);
|
||||||
|
|
||||||
// wss.clients.forEach((client: any) => {
|
wss.clients.forEach((client: any) => {
|
||||||
// if (client.readyState === WebSocket.OPEN) {
|
if (client.readyState === WebSocket.OPEN) {
|
||||||
// const message = JSON.stringify({ template: "report2", reportName: "report2", data: { data } });
|
const message = JSON.stringify({ template: "report2", reportName: "report2", data: { data } });
|
||||||
// console.log("📤 Sending data to client:", message);
|
console.log("📤 Sending data to client:", message);
|
||||||
// client.send(message, (err:any) => {
|
client.send(message, (err:any) => {
|
||||||
// if (err) {
|
if (err) {
|
||||||
// console.error("❌ Error sending message:", err);
|
console.error("❌ Error sending message:", err);
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
|
|
||||||
return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } });
|
// return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue