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.

Do not use localhost:3000 as default in production

See original GitHub issue

What problem does this feature solve?

If eveything else fails, baseURL will default to http://localhost:3000.

While this is nice in dev environement, it might cause production environement to use http://localhost:3000 as default, if not configured properly.

This lead to error in my deployment because I didn’t configure the module correctly but din’t realise my mistake until it was too late.

I believe that a better behaviour would be to throw ASAP in that case, preventing the deployment of faulty code.

What does the proposed changes look like?

let defaultPort =
  // ...
  (process.env.NODE_ENV === 'development' && 3000)

let defaultHost =
  // ...
  (process.env.NODE_ENV === 'development' && 'localhost')

if (!defaultPort || !defaultHost) throw new Error('Configuration error')
<div align="right">This feature request is available on Nuxt community (#c267)</div>

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:11
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
nzakascommented, Oct 18, 2019

This is a really confusing default behavior, it took me a while to figure out why my API calls were failing. I agree with @matthieusieben – when I say /api/foo, it is logical to expect that this request will go to the same host/port as the page that is calling it.

1reaction
pi0commented, Oct 22, 2019

@manniL Indeed baseURL is auto-generated with port/host of the listener server if not provided:

https://github.com/nuxt-community/axios-module/blob/dev/lib/module.js#L17

This issue is requesting to make setting baseURL manually mandatory for non-dev and not using server host/port to generate it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is localhost 3000? - reactjs - Stack Overflow
Localhost means that it's your computer that is hosting the app, and it doesn't mean that it's accessible on other computers. 3000 is...
Read more >
You should never ever run directly against Node.js in ...
First off, let's address the statement “never run apps directly against Node in production”. Never run directly against Node in production.
Read more >
Express/Node introduction - Learn web development | MDN
With the server running, you could go to localhost:3000 in your browser to see the example response returned. Importing and creating modules. A ......
Read more >
How to Easily Set-up Node Config (Best Practices)
Putting the default port on which the app will bind into the code is not really an issue; however, the login credentials for...
Read more >
Server Options - Vite
The first case is when localhost is used. Node.js under v17 reorders the result of DNS-resolved addresses by default. When accessing localhost ,...
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