Commit ef7057b9 authored by Kannan V M's avatar Kannan V M
Browse files

Handle namespace url and serving path from config

parent e8861352
module.exports = {
port: 3000,
filename: "knowledge.json",
username: "treehouse",
password: "fsc2kMod!"
rooms: {"":"en", "":"ml", "":"hi", "":"ma"},
modNamespace: "",
}
......@@ -21,7 +21,13 @@ server.listen(port, () => {
// assign static path to public folder
app.use(express.static(path.join(__dirname, '/public/')));
app.get(['/mod_en', '/mod_ml', '/mod_hi'], (req, res) => {
const modRooms = [];
Object.keys(config.rooms).forEach((key) => {
modRooms.push(`/${key}`);
});
app.get(modRooms, (req, res) => {
res.sendFile(path.join(__dirname, '/public/mod.html'));
});
......@@ -30,7 +36,7 @@ app.get(['/en', '/ml', '/hi'], (req, res) => {
});
const userNamespace = io.of('/user');
const modNamespace = io.of('/mod'); // set auth
const modNamespace = io.of(config.modNamespace);
const leafIds = [];
for (let i = 7; i < 332; i += 1) {
......@@ -99,8 +105,9 @@ userNamespace.on('connection', (socket) => {
});
modNamespace.on('connection', (socket) => {
const { roomId } = socket.handshake.query;
if (roomId === 'en' || roomId === 'ml' || roomId === 'hi') {
const { roomName } = socket.handshake.query;
const roomId = config.rooms[roomName];
if (roomId) {
socket.join(roomId);
modNamespace.to(roomId).emit('leaves data', leavesData[roomId]);
......
const ROOM = window.location.href.split('_')[1];
const ROOM = window.location.href.split('/')[3];
const mod = io.connect('/mod',{
query: {
roomId: ROOM,
roomName: ROOM,
}
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment