- 
                Notifications
    
You must be signed in to change notification settings  - Fork 29.7k
 
Closed
Description
Questions
- Is this how we should add Socket.io to a serverless API route?
 - Can that be done without requiring 
httpand/ormicro@9.3.5-canary.1or any other version of it (without that at all)? - Can Next.js accept trailing slashes after route names?
 
Error
When connecting keeps returning 404 not found becasue Socket.io adds a slash after route.
http://localhost:3000/api/route/?EIO=3&transport=polling
Whereas Next.js would only accept something like this apparently:
http://localhost:3000/api/route?EIO=3&transport=polling
Code
./pages/api/route.js
const http = require('http');
const micro = require('micro');
const server = micro((req, res) => {
  console.log('endpoint connection')
});
const options = { path: '/api/route', cookie: false };
const io = require('socket.io')(new http.Server(server), options);
function connection(socket) {
  console.log('socket.io connection');
}
io.on('connection', connection);
export default server;./pages/index.js
[...]
const socket = io('http://localhost:3000', { path: '/api/route' });
[...]Metadata
Metadata
Assignees
Labels
No labels