{"id":21269665,"url":"https://github.com/s-fabian/websocket-issue","last_synced_at":"2025-07-11T05:31:18.026Z","repository":{"id":167218353,"uuid":"642792078","full_name":"s-fabian/websocket-issue","owner":"s-fabian","description":null,"archived":false,"fork":false,"pushed_at":"2023-05-19T21:05:59.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-11-16T09:32:08.309Z","etag":null,"topics":["http","nextjs","node","websocket"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/s-fabian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-05-19T11:00:50.000Z","updated_at":"2023-11-16T09:32:18.380Z","dependencies_parsed_at":"2023-11-16T09:42:18.487Z","dependency_job_id":null,"html_url":"https://github.com/s-fabian/websocket-issue","commit_stats":null,"previous_names":["heroclay/websocket-issue","s-fabian/websocket-issue"],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-fabian%2Fwebsocket-issue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-fabian%2Fwebsocket-issue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-fabian%2Fwebsocket-issue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-fabian%2Fwebsocket-issue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/s-fabian","download_url":"https://codeload.github.com/s-fabian/websocket-issue/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225693748,"owners_count":17509227,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","nextjs","node","websocket"],"created_at":"2024-11-21T08:09:55.276Z","updated_at":"2024-11-21T08:09:55.822Z","avatar_url":"https://github.com/s-fabian.png","language":"JavaScript","readme":"# Websocket issue\n\n## Scenario one: `yarn without-next`\n\n1. Visit http://localhost:3000/ws/html\n2. The browser tries to connect to the websocket server\n3. The server receives the request, logs \"Websocket trying to connect!\"\n4. The server handles the request (in this case returns a 501)\n5. The `error` or `connect` event of the websocket is triggered\n\n## Scenario two: `yarn with-next`\n\n1. Visit http://localhost:3000/\n2. Close the tab\n3. Visit http://localhost:3000/ws/html\n4. The browser tries to connect to the websocket server\n5. The server doesn't receive the request, doesn't log \"Websocket trying to connect!\"\n6. No event is triggered on the websocket\n\n## Solution: `yarn with-next-fix`\n\nHow? Well, the problem is caused by `app?.getRequestHandler()()`.\n\nThis function adds a listener onto the server matching the `upgrade` event.\n\nThis can be prevented by overriding the function that's used to add an event listener\ninto caching the function for the event handler into a local variable.\n\nNow you can call this variable if the url matches `/_next/webpack-hmr`,\notherwise you can use your own websocket logic.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs-fabian%2Fwebsocket-issue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fs-fabian%2Fwebsocket-issue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs-fabian%2Fwebsocket-issue/lists"}