question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`url` attribute is `undefined` server-side

See original GitHub issue
  • I’ve searched for any related issues and avoided creating a duplicate issue.

Description

On server-side WebSocket instances, url attribute is undefined. This is because it’s being set at https://github.com/websockets/ws/blob/237960e915b3f41b8c7aabfa5c938171976f2978/lib/websocket.js#L475-L481, that’s only being called when initAsClient() function is being called, and this is detected if constructor was called setting address as null. This is fine, but for homogeneity and server-side operation, I would set url attribute to the actual url being used by client-side to create the WebSocket instance, recreating the full URL by combining the request host, path and query (fragment is not send to the server). Main drawback would be that since now we would have an address, how to detect if it’s a client-side or server-side WebSocket instance. Not sure if setting it afterwards at WebSocket Server completeUpgrade() method, or by passing a custom option to flag the instance as server side.

Reproducible in:

  • version: 7.3.1
  • Node.js version(s): 15.0.1
  • OS version(s): Ubuntu 20.04

Steps to reproduce:

  1. Create a WebSocket Server instance
  2. Connect from a client
  3. Read socket.url attribute at server-side

Expected result:

A string with the url used by the client to create the WebSocket connection

Actual result:

undefined

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pirannacommented, Aug 21, 2021

and thanks 😄

1reaction
lpincacommented, Aug 21, 2021

It would be easy as websocket.url is already a getter so a simple check for this._isServer would do the job but throwing a new error is semver-major. I’ll add it to the todo list for the next major version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Post request returns undefined on the server side
You will get the the query string parameters in "req.query" if you are using Express with NodeJS. Try this var pacote = req.query.idPacote;....
Read more >
Lightning server-side method returning "undefined"
Lightning server-side method returning "undefined" - Salesforce Stack Exchange. Stack Overflow for Teams – Start collaborating and sharing ...
Read more >
Server-side include commands for HTTP Server - IBM
This topic provides information about server-side include (SSI) commands for the IBM HTTP ... However, the file attribute doesn't respect URL-space aliases.
Read more >
JavaScript undefined Property - W3Schools
The undefined property indicates that a variable has not been assigned a value, or not declared at all. Browser Support. undefined() is an...
Read more >
Docs • Svelte
SvelteKit utilizes Vite to build your code and handle server-side rendering ... (or if its initial value is undefined ) when instantiating the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found