0

I'm setting up a new project. In it I used a proxy settings inside my package.json.

Now, everytime I use fetch I do this:

fetch("/foo")

instead of this:

fetch("http://www.bar.com/foo")

This is all good while I'm in development mode. However, I dont know how can I supply my fetch() with the appropriate base url while my app is in production mode.

Any help is much appreciated. Thank you!

1 Answer 1

1

1) Create config.json and add base url key value pair in json format as shown below.

{
  "baseUrl": "http://www.bar.com/",
}

2) For CRUD operations through fetch or any other library use baseUrl from config. You could change baseUrl using webpack while building for different environments like production or development.

Hope that helps!!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.