47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
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",
|
|
});
|
|
};
|