feat: socketio event
This commit is contained in:
parent
0a1265b78c
commit
25752dac19
9 changed files with 200 additions and 8 deletions
|
|
@ -2,6 +2,8 @@ import "dotenv/config";
|
|||
import express from "express";
|
||||
import swaggerUi from "swagger-ui-express";
|
||||
import cors from "cors";
|
||||
import { createServer } from "http";
|
||||
import { Server } from "socket.io";
|
||||
|
||||
import { RegisterRoutes } from "./routes";
|
||||
import errorHandler from "./middlewares/exception";
|
||||
|
|
@ -9,6 +11,7 @@ import rabbitmq from "./rabbitmq";
|
|||
|
||||
import swaggerSpecs from "./swagger.json";
|
||||
import { handler as amqHandler } from "./rabbitmq/handler";
|
||||
import { setInstance } from "./lib/websocket";
|
||||
|
||||
const PORT = +(process.env.PORT || 80);
|
||||
|
||||
|
|
@ -31,7 +34,24 @@ app.use((_req, res, _next) => {
|
|||
res.sendFile(`${process.cwd()}/static/index.html`);
|
||||
});
|
||||
|
||||
app.listen(PORT, "0.0.0.0", () =>
|
||||
const server = createServer(app);
|
||||
const io = new Server(server, {
|
||||
cors: {
|
||||
origin: "*",
|
||||
},
|
||||
});
|
||||
|
||||
setInstance(io);
|
||||
|
||||
io.on("connection", (socket) => {
|
||||
console.log("User Connected");
|
||||
|
||||
socket.on("disconnected", () => {
|
||||
console.log("User Disconnected");
|
||||
});
|
||||
});
|
||||
|
||||
server.listen(PORT, "0.0.0.0", () =>
|
||||
console.log(`[APP] Application is running on http://localhost:${PORT}`),
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue