bdefore / universal-redux-jwt

An example of universal-redux npm package with JWT authentication
24 stars 7 forks source link

Where are the globals ___API_PORT___ and ___API_HOST___ coming from? #6

Open bartolkaruza opened 8 years ago

bartolkaruza commented 8 years ago

I'm trying to figure out the way the isomorphic fetcher is implemented and I've run into some confusion about globals. api port and host are loaded from the .env file, they are used as globals in fetcher.js. Where and how do they transition from env variables on process.env to UR globals?

bdefore commented 8 years ago

They use Webpack's DefinePlugin to do so. https://github.com/bdefore/universal-redux/blob/master/bin/merge-configs.js#L96-L98.

bartolkaruza commented 8 years ago

Ah yeah, that's what I meant to say. They are not defined as globals in univseral.redux.config.js:

https://github.com/bdefore/universal-redux-jwt/blob/master/config/universal-redux.config.js#L73-L97

sai-prasanna commented 8 years ago

Server side rendering API request scenario -

API_HOST = server-api.com Current server for rendering react in server side = server.com server.com proxies requests to server-api.com using express-jwt-proxy,

But when server.com express instance makes api request(for server side rendering ) to server-api.com, in current implementation, if it calls server-api.com directly using superagent, wont it create a conflict? Because client is logged in , has a session cookie, but server implementation of fetcher doesnt send token by checking for the cookie in the request?

APIClient implementation in react universal hot package solved this by setting server req to the APIClient constructor on server side, though that forces the use of middleware to be initallized with api client created with req constructor initially, but it solves this problem ..