#socket io admin ui issue

4 messages · Page 1 of 1 (latest)

hearty girder
#

when using the socket io admin ui it stops the server from receiving events and idk why please help me heres my code

const chalk = require('chalk');
const express = require('express');
const http = require('http');
const socketIO = require('socket.io');
const { Server } = require('socket.io');
const { instrument } = require('@socket.io/admin-ui');
const bcrypt = require('bcrypt');

const app = express();
const server = http.createServer(app);
const io = socketIO(server);

app.set('view engine', 'ejs');

app.get('/', (req, res) => {
  res.render('index');
});

app.get('/chatroom', (req, res) => {
  res.render('chat');
});

io.on('connection', (socket) => {
  console.log('A user connected');

  socket.on('send_message', (data) => {
    console.log('Message received:', data);
    socket.emit('receive_message', { message: data.message });
  });

  socket.on('disconnect', () => {
    console.log('A user disconnected');
  });
});

(async () => {
  const hashedPassword = await bcrypt.hash('123', 14);

  const io2 = new Server(server, {
    cors: {
      origin: ['https://admin.socket.io'],
      credentials: true,
    },
  });

  instrument(io2, {
    namespaceName: '/admin',
    auth: {
      type: 'basic',
      username: '123',
      password: hashedPassword,
    },
  });

  server.listen(3000, () => {
    console.log(
      `${chalk.magenta(
        `Server started. Connect with this link:\nhttp://2.222.0.29:3000`
      )}${chalk.red(
        `\n\nAt any time click in the console and press ctrl+c to stop the website.`
      )}${chalk.yellow(`\n\nMade by ZSStudios.`)}`
    );
  });
})();

#

🇭 🇪 🇱 🇵

#

im making a website for my friend and the admin ui has just broken everything

#

brb