Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Works fine in version 2.x but not in version 4.1. #3962

Closed
bilalbaz1 opened this issue Jun 6, 2021 · 2 comments
Closed

Works fine in version 2.x but not in version 4.1. #3962

bilalbaz1 opened this issue Jun 6, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@bilalbaz1
Copy link

Hi.
I want to use api and socket.io on the same port. That way it's cheaper on hereku.
The problem is; socket.io works fine in version 2.x but not in version 4.1. It doesn't give any error either. What could be the problem? The codes are like this;

const app = require('express')();
const http = require('http').createServer(app);

const userRouter = require('./router/userRouter');

const errMiddleware = require('./middleware/errMiddleware');

const PORT = process.env.PORT || 3000;

app.use('/api/users', userRouter);


app.get('/', (req, res) => {
  res.json({ "mesaj": "hoşgeldin!" });
});

app.use(errMiddleware);

http.listen(PORT, () => {
  console.log(`Listening on ${PORT}`);
});


const io = require("socket.io")(http, {
  cors: {
    origin: "*",
   methods: ["GET", "POST"],
  },
});

io.on("connection", (socket) => {

console.log("----- connection");

  socket.on("odaya_gir", (odaId, data) => {
    socket.join(odaId);
  });

  socket.on("disconnect", () => {
    console.log("****** disconnect");
  });


});

package

"express": "^4.17.1",
"socket.io": "^4.1.2",
@bilalbaz1 bilalbaz1 added the bug Something isn't working label Jun 6, 2021
@darrachequesne
Copy link
Member

I don't see anything wrong in the code you provided. Could you please provide a complete example?

@qiulang
Copy link

qiulang commented Jun 10, 2021

Today I upgraded my socket.io from 2.x to 4.1 and it works fine. So I was wondering did you upgrade socket.io-client or set allowEIO3: true ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants