Merge branch 'adiDev' into develop

This commit is contained in:
AdisakKanthawilang 2025-03-05 18:25:51 +07:00
commit d76a7f90bd

View file

@ -13,19 +13,19 @@ 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 { WebSocketServer } from "ws";
// import http from "http"; import http from "http";
// export const wss = new WebSocketServer({ noServer: true, export const wss = new WebSocketServer({ noServer: true,
// path: "/api/v1/org/socket", path: "/api/v1/org/socket",
// }); });
async function main() { async function main() {
await AppDataSource.initialize(); await AppDataSource.initialize();
const app = express(); const app = express();
// สร้างเซิร์ฟเวอร์ HTTP // สร้างเซิร์ฟเวอร์ HTTP
// const server = http.createServer(app); const server = http.createServer(app);
app.use( app.use(
cors({ cors({
@ -38,6 +38,15 @@ async function main() {
app.use("/", express.static("static")); app.use("/", express.static("static"));
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument)); app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use((req, res, next) => {
console.log(`Request received at: ${req.url}`);
next();
});
app.get('/api', (req, res) => {
res.send('API route is working!');
});
RegisterRoutes(app); RegisterRoutes(app);
app.use(error); app.use(error);
@ -77,14 +86,14 @@ async function main() {
}); });
// 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();
@ -97,36 +106,36 @@ async function main() {
runMessageQueue(); runMessageQueue();
// การจัดการคำขออัปเกรดจาก HTTP เป็น WebSocket // การจัดการคำขออัปเกรดจาก HTTP เป็น WebSocket
// server.on("upgrade", (request:any, socket:any, head:any) => { server.on("upgrade", (request:any, socket:any, head:any) => {
// console.log("🔹 Handling upgrade request..."); console.log("🔹 Handling upgrade request...");
// wss.handleUpgrade(request, socket, head, (ws:any) => { wss.handleUpgrade(request, socket, head, (ws:any) => {
// console.log("🔹 WebSocket connection established"); console.log("🔹 WebSocket connection established");
// wss.emit("connection", ws, request); wss.emit("connection", ws, request);
// }); });
// }); });
// wss.on("connection", (ws:any) => { wss.on("connection", (ws:any) => {
// console.log("✅ Client connected to WebSocket"); console.log("✅ Client connected to WebSocket");
// ws.on("close", () => { ws.on("close", () => {
// console.log("❌ Client disconnected"); console.log("❌ Client disconnected");
// }); });
// ws.on("error", (error:any) => { ws.on("error", (error:any) => {
// console.error("WebSocket error:", error); console.error("WebSocket error:", error);
// }); });
// }); });
// // ตั้งค่า Express routes // ตั้งค่า Express routes
// app.get('/', (req, res) => { app.get('/', (req, res) => {
// res.send('Hello from Express!'); res.send('Hello from Express!');
// }); });
// server.listen(APP_PORT, APP_HOST, () => { server.listen(APP_PORT, APP_HOST, () => {
// console.log(`[APP] Application is running on: http://${APP_HOST}:${APP_PORT}`); 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] Swagger on: http://${APP_HOST}:${APP_PORT}/api-docs`);
// console.log("[APP] HTTP Server is listening on current port"); console.log("[APP] HTTP Server is listening on current port");
// }); });
} }