erikras / react-redux-universal-hot-example

A starter boilerplate for a universal webapp using express, react, redux, webpack, and react-transform
MIT License
12k stars 2.5k forks source link

async call to work to load data from api server #1328

Open Swapnilchavan18 opened 7 years ago

Swapnilchavan18 commented 7 years ago

return { types: [LOAD, LOAD_SUCCESS, LOAD_FAIL], promise: (client) => client.get('http://localhost:3030/loadInfo') }; Above part I want to call as getting data from another server api like below. return { types: [LOAD, LOAD_SUCCESS, LOAD_FAIL], promise: (client) => client.get('http://test.com/api') }; How to do this, please explain.

Swapnilchavan18 commented 7 years ago

seems to be no one willing to help for this repository. I always get Cannot read property 'promise' of undefined

TravnikovDev commented 7 years ago

@Swapnilchavan18 Please, RTFM https://github.com/erikras/react-redux-universal-hot-example/blob/master/docs/ApiConfig.md

Swapnilchavan18 commented 7 years ago

My problem is that it does not render server side api called data http://stackoverflow.com/questions/40912655/server-side-data-fetching-does-not-work-in-this-example-https-github-com-erikr

jdosullivan commented 7 years ago

I'll try to explain what is trying to be conveyed in easier terms. The apiClient used in this project prepends the request with a baseUrl.

The baseUrl is set in the apiClient.js. By default it's set to a 'http://' + config.apiHost + ':' + config.apiPort;' when invoked server side, with config values being:

apiHost: process.env.APIHOST || 'localhost',
  apiPort: process.env.APIPORT || 3030,

So when you issue your client.get call to http://test.com/api') it issues a request to http://localhost:3030/http://test.com/api` which obviously will return nothing.

You need to follow TPABHuKOB's link and learn how to remove this prepending of the base url.

Hope that makes sense.