content: Websocket error using alternative server framework
Version
@nuxt/content: 1.3.2 nuxt: 2.12.2
Reproduction Link
https://github.com/mikeburgh/nuxt-hapi-content Created with npx create-nuxt-app -selecting hapi as the server framework -then adding in the @nuxt/content module
Steps to reproduce
Clone repo Run npm run dev Browse to : http://localhost:3000
What is Expected?
No errors in the console
What is actually happening?
Console is showing an error
ERROR Cannot read property 'length' of undefined 20:57:36
at WebSocket.setSocket (node_modules/@nuxt/content/node_modules/ws/lib/websocket.js:165:14)
at WebSocketServer.completeUpgrade (node_modules/@nuxt/content/node_modules/ws/lib/websocket-server.js:322:8)
at WebSocketServer.handleUpgrade (node_modules/@nuxt/content/node_modules/ws/lib/websocket-server.js:245:10)
at WS.handleUpgrade (node_modules/@nuxt/content/lib/ws.js:21:21)
at WS.serve (node_modules/@nuxt/content/lib/ws.js:17:10)
at node_modules/@nuxt/content/lib/middleware.js:11:15
at call (node_modules/connect/index.js:239:7)
at next (node_modules/connect/index.js:183:5)
at next (node_modules/connect/index.js:161:14)
at WebpackBundler.middleware (node_modules/@nuxt/webpack/dist/webpack.js:5410:5) (repeated 1 times)
The error seems to be caused by the serve method in @nuxt/content/lib/ws.js and happens with both Hapi and express frameworks.
serve (req) {
this.handleUpgrade(req, req.socket, undefined)
}
Changing the undefined to an empty array solves it, although not sure if head should actually be something ? Happy to send a PR if head just needs to be an empty array ?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 8
- Comments: 16 (2 by maintainers)
Commits related to this issue
- fix: set header to empty array Fixes #136 — committed to nuxt/content by Atinux 4 years ago
- fix: set header to empty string if undefined (#620) Fixes #136 — committed to nuxt/content by Atinux 4 years ago
- docs(examples): add queries examples (#136) Co-authored-by: Yaël Guilloux <yael.guilloux@gmail.com> — committed to nuxt/content by clemcode 2 years ago
I have a similar problem
I’m having that issue without an alternative server framework. I’m using nuxt defaults
I had similar problem. I was running nuxt locally behind nginx reverse proxy and when I enabled websockets in nginx, problem disappeared. Maybe it will help somebody.
I think I’ve managed to fix this error with the following: