You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to make a websocket server using socket.io and upon polling I get a 404 error.
This is my next.js server code:
`import { Server } from "socket.io"
import axios from "axios"
export default async function socketHandler(req, res) {
if (res.socket.server.io) {
console.log('Socket is already running')
} else {
console.log('Socket is initializing')
const io = new Server(res.socket.server, {
allowRequest: (req, callback) => {
callback(null, false);
}
})
res.socket.server.io = io
Many people have not been able to solve this and for me, I could not find any appropriate solution anywhere online either.
I really appreciate any help you can provide.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to make a websocket server using socket.io and upon polling I get a 404 error.
This is my next.js server code:
`import { Server } from "socket.io"
import axios from "axios"
export default async function socketHandler(req, res) {
if (res.socket.server.io) {
console.log('Socket is already running')
} else {
console.log('Socket is initializing')
const io = new Server(res.socket.server, {
allowRequest: (req, callback) => {
callback(null, false);
}
})
res.socket.server.io = io
}
res.end()
}`
Many people have not been able to solve this and for me, I could not find any appropriate solution anywhere online either.
I really appreciate any help you can provide.
Beta Was this translation helpful? Give feedback.
All reactions