/
githubmirror
/
socket.io
Обзор
Документация
Войти
/
githubmirror
/
socket.io
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
examples/nextjs-app-router/server.js
29 строк
715 B
Damien Arrachequesne
docs: add example with Next.js (with app router)
27 мар 2024, 13:02
Не верифицирован
27 мар 2024, 13:02
61f4449
Код
Авторство
О чём код?
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}`); }); });