mirror of
https://github.com/socketio/socket.io.git
synced 2026-01-10 15:37:58 -05:00
30 lines
715 B
JavaScript
30 lines
715 B
JavaScript
import { createServer } from "http";
|
|
import next from "next";
|
|
import { Server } from "socket.io";
|
|
|
|
const dev = process.env.NODE_ENV !== "production";
|
|
const hostname = "localhost";
|
|
const port = 3000;
|
|
// when using middleware `hostname` and `port` must be provided below
|
|
const app = next({ dev, hostname, port });
|
|
const handler = app.getRequestHandler();
|
|
|
|
app.prepare().then(() => {
|
|
const httpServer = createServer(handler);
|
|
|
|
const io = new Server(httpServer);
|
|
|
|
io.on("connection", (socket) => {
|
|
// ...
|
|
});
|
|
|
|
httpServer
|
|
.once("error", (err) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
})
|
|
.listen(port, () => {
|
|
console.log(`> Ready on http://${hostname}:${port}`);
|
|
});
|
|
});
|