DEV Community

Discussion on: Svelte 3 - How to connect your app with a Rest API Axios

Collapse
 
hydracorey profile image
Corey Vincent

What did you mean by:

const axiosAPI = axios.create({
  baseURL : "https://pokeapi.co/api/v2/" // it's not recommended to have this info here.
});
Enter fullscreen mode Exit fullscreen mode

Are you just suggesting we get the 'baseURL' constant from somewhere more global, or that there's a way to secure/hide that value? I was under the impression the front end can be seen by pretty much anyone...

Collapse
 
rubendutchtelco profile image
RubenDutchtelco

You are correct about the fact that all front-end code is always visible to the end user.

I think the recommended method the author is referring to is a .env like file (npmjs.com/package/dotenv). Which does not hide the values but makes them more variable and easier to change without having to alter your code.
You might want your front-end connecting to different base URL's depending on what environment it is running (dev, staging, prod).

Collapse
 
hydracorey profile image
Corey Vincent

Thanks for the response. Your points make sense.