feat: replace separate WebSocket server with Next.js custom server#5138
Draft
feat: replace separate WebSocket server with Next.js custom server#5138
Conversation
Contributor
|
|
Overall Grade Focus Area: Reliability |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| JavaScript | Feb 28, 2026 9:15a.m. | Review ↗ |
- Create apps/nextjs/server.ts custom server integrating WebSocket via ws - Update nextjs scripts to use custom server for dev and start - Update root start script to remove separate ws server process - Update client tRPC URL to connect to port 3000 in dev - Update nginx.conf to route /websockets to port 3000 - Update Dockerfile and run.sh for integrated server - Disable standalone ws server dev script - Add benchmark-memory.sh script Co-authored-by: ajnart <49837342+ajnart@users.noreply.github.com>
…benchmark script Co-authored-by: ajnart <49837342+ajnart@users.noreply.github.com>
…ering Co-authored-by: ajnart <49837342+ajnart@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Replace ws server with custom Next.js server for POC
feat: replace separate WebSocket server with Next.js custom server
Feb 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Homarr
Thank you for your contribution. Please ensure that your pull request meets the following pull request:
pnpm build, autofix withpnpm format:fix)devbranchx,y,ior any abbrevation)POC to eliminate the standalone
apps/websocketNode.js process by integrating the WebSocket server directly into a Next.js custom server, as described in the Socket.io guide.Approach
apps/nextjs/server.tscreates a singlehttp.createServerthat:next().getRequestHandler()upgradeon/websockets→ws.WebSocketServer({ noServer: true })applyWSSHandlerwith identical tRPC context/auth as the old standalone serverChanges
apps/nextjs/server.ts— Custom server: Next.js + integrated WS via@trpc/server/adapters/wsapps/nextjs/package.json—devusestsx server.ts,startusesnode customServer.cjs, build step added for esbuild bundlingapps/nextjs/…/trpc.tsx— WebSocket URL changed from port 3001 → 3000 (same process now)apps/websocket/package.json—devscript is now a no-oppackage.json—startno longer spawnswssServer.cjsscripts/run.sh— Singlenode apps/nextjs/customServer.cjsreplaceswssServer.cjs+server.jsnginx.conf—/websocketsproxy target changed to port 3000Dockerfile— CopiescustomServer.cjsinstead ofwssServer.cjsscripts/benchmark-memory.sh— Memory measurement script for both approachesBenchmark (dev mode, idle after startup)
One fewer Node.js V8 heap plus reduced worker spawning overhead.
Notable detail
next/dist/server/node-environment-baselinemust be imported before anything else — it setsglobalThis.AsyncLocalStoragewhich Next.js internals require at module load time.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
fonts.googleapis.com/home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/homarr/homarr/node_modules/.bin/next build l/openssl/include k/v1�� bcrypt --external:@opentelemetry/api --external:deasync --external:cpu-features --loader:.html=text --loader:.scss=text --loader:.node=text credential.username -features/build/node_gyp_bins/as(dns block)homarr.dev/opt/hostedtoolcache/node/24.13.1/x64/bin/node /opt/hostedtoolcache/node/24.13.1/x64/bin/node --require /home/REDACTED/work/homarr/homarr/node_modules/tsx/dist/preflight.cjs --import file:///home/REDACTED/work/homarr/homarr/node_modules/tsx/dist/loader.mjs ./src/docs/codegen.ts --global node_modules/.bin/sh user.name l/config(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.