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.

TypeError crashing application when using relative URL from axios

See original GitHub issue

I got the following error coming from follow-redirects:

/.../node_modules/follow-redirects/index.js:598
  const dot = subdomain.length - domain.length - 1;
                                        ^
TypeError: Cannot read property 'length' of null
    at isSubdomain (/.../node_modules/follow-redirects/index.js:598:41)
    at RedirectableRequest._processResponse ((/.../node_modules/follow-redirects/index.js:432:7)
    at ClientRequest.RedirectableRequest._onNativeResponse ((/.../node_modules/follow-redirects/index.js:57:10)
    at Object.onceWrapper (events.js:520:26)
    at ClientRequest.emit (events.js:400:28)
    at ClientRequest.emit (domain.js:475:12)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:647:27)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:127:17)
    at Socket.socketOnData (_http_client.js:515:22)
    at Socket.emit (events.js:400:28)

and it happens when HTTP client (axios) is trying to do GET request on relative URL: /console/external/content?url=https%3A%2F%2F...%2Faws.png.

From my quick investigation it seems like currentHost passed to isSubdomain function is null, but inside that function it is assumed that this parameter is a string.

Attachments: This are dumps of some data in RedirectableRequest.prototype._processResponse function:

Environment:

  • node - v14.18.1
  • axios - v0.26.1
  • follow-redirects - v1.15.1
  • nginx HTTPS webserver running on localhost

Not sure if it is on follow-redirects or on axios side, but that specific error is not handled and it crashes the app. Other errors like invalid URL when using absolute URLs are handled flawlessly.

Let me know if any additional data needed or if I should pass this issue to axios guys.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13

github_iconTop GitHub Comments

1reaction
RubenVerborghcommented, Sep 13, 2022

Thanks @qooban. v1.15.2 will now handle this gracefully by defaulting to localhost (6e2b86da90cde81f15a5ba1732a41fd1291f14d3), as Node does. However, I still recommend you use the full URL, as it seems to be a pure coincidence that it is indeed localhost in your case 🙂

0reactions
qoobancommented, Sep 13, 2022

Yeah, you’re right. When using axios in browser relative URL should work, but in node.js environment (this is my case) it has no way to know how to transform it, so baseURL should be specified in axios config. When I set it ({ baseURL: 'https://localhost' }), my migration script is not crashing anymore.

Thanks for your patience and willingness to find the reason for the problem!

Read more comments on GitHub >

github_iconTop Results From Across the Web

relative URL not working with axios in node - Stack Overflow
You can't use a relative URL in this scenario because there's nothing for it to be relative to - you're executing code in...
Read more >
Error when using a local URL on baseURL #1228 - GitHub
That is, I'm creating an axios instance with baseUrl: 'http://localhost:8000' but all the requests are throwing ECONNREFUSED on 127.0.0.1:80 .
Read more >
Errors | Node.js v19.3.0 Documentation
For all EventEmitter objects, if an 'error' event handler is not provided, the error will be thrown, causing the Node.js process to report...
Read more >
How to connect Flask to ReactJs - DEV Community ‍ ‍
Now let's go through the new lines of code added to the app.js file. At the top of the file, the useState hook...
Read more >
Fullstack part3 | Deploying app to internet
Because of our situation, both the frontend and the backend are at the same address, we can declare baseUrl as a relative URL....
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