0

I am using the boilerplate on https://github.com/react-boilerplate/react-boilerplate . The problem is that when I'm hitting API's It's returning error 404. I'm not able to get from where it is setting up the host (which is always going localhost). no CORS error is also coming up on browser.

Prior to this I was working on create-react-app, there I simple put a "proxy" property in package.json and everything worked fine.

Today I set up this boilerplate for the first time and I would say it's a lil confusing _:)

Tripti Rawat
  • 645
  • 7
  • 19
  • More information on which API you are trying to hit would help. – praveenweb Feb 09 '18 at 11:31
  • No actually my concern is more about where do we set the base of the request URL...eg I have to hit API //192.168.0.7/master/api/login....I'm already ofcrs providing the '/master/api/login' part in my saga....but the base ie '192.168.0.7' where do I set it? Is there a config file making method I should be following? Or some internal method( like in the case of create-react-app) is available? PS let me know if my comment made any sense. – Tripti Rawat Feb 09 '18 at 11:41

2 Answers2

0

You can specify API base url like this:

const API = process.env.NODE_ENV !== 'production' ? 'http://google.com' : 'http://localhost:5000'

So in development it will always point to localhost and in production it will point to other your prod server.

kurumkan
  • 2,635
  • 3
  • 31
  • 55
0

For people still searching, all you need is to create something like this in server/index.js

app.get('/api/user', (req, res, next) => {
  let parsedBody = JSON.parse(req.body)

  res.send({ express: 'Hello From Express.' });
});

on client side request to /api/user

axios.get(`/api/user`)
  .then(function (response) {
    console.log("/api/user response", response);
  })
  .catch(function (error) {
    console.log(error);
  });

cheers