feat(server): added in admin section of socketio
This commit is contained in:
51
backend/src/socket.io/serverSetup.ts
Normal file
51
backend/src/socket.io/serverSetup.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import type { Server as HttpServer } from "node:http";
|
||||
//import { dirname, join } from "node:path";
|
||||
//import { fileURLToPath } from "node:url";
|
||||
import { instrument } from "@socket.io/admin-ui";
|
||||
import { Server } from "socket.io";
|
||||
|
||||
//const __filename = fileURLToPath(import.meta.url);
|
||||
//const __dirname = dirname(__filename);
|
||||
|
||||
export const setupSocketIORoutes = (baseUrl: string, server: HttpServer) => {
|
||||
const io = new Server(server, {
|
||||
path: `${baseUrl}/api/socket.io`,
|
||||
cors: {
|
||||
origin: ["http://localhost:3000", "https://admin.socket.io"],
|
||||
credentials: true,
|
||||
},
|
||||
});
|
||||
|
||||
io.on("connection", (s) => {
|
||||
console.info(s.id);
|
||||
});
|
||||
|
||||
// admin stuff for socket io
|
||||
// app.use(
|
||||
// express.static(
|
||||
// join(__dirname, "../../../node_modules/@socket.io/admin-ui/dist"),
|
||||
// ),
|
||||
// );
|
||||
|
||||
// app.get(baseUrl + "/admindashboard", (_, res) => {
|
||||
// res.sendFile(
|
||||
// join(
|
||||
// __dirname,
|
||||
// "../../../node_modules/@socket.io/admin-ui/dist/index.js",
|
||||
// ),
|
||||
// );
|
||||
// });
|
||||
const admin = io.of("/admin");
|
||||
admin.on("connection", () => {
|
||||
console.info("Connected to admin userspace");
|
||||
});
|
||||
instrument(io, {
|
||||
auth: false,
|
||||
//namespaceName: "/admin",
|
||||
});
|
||||
//setup all the routes
|
||||
// app.use(`${baseUrl}/api/datamart`, runQuery);
|
||||
// app.use(`${baseUrl}/api/datamart`, addQuery);
|
||||
// app.use(`${baseUrl}/api/datamart`, updateQuery);
|
||||
// just sending a get on datamart will return all the queries that we can call.
|
||||
};
|
||||
@@ -9,6 +9,8 @@ export const allowedOrigins = [
|
||||
"http://localhost:4000",
|
||||
"http://localhost:4001",
|
||||
"http://localhost:5500",
|
||||
"https://admin.socket.io",
|
||||
"https://electron-socket-io-playground.vercel.app",
|
||||
`${process.env.URL}`,
|
||||
];
|
||||
export const lstCors = () => {
|
||||
|
||||
Reference in New Issue
Block a user