cmosguy / react-redux-auth0

Using kriasoft/react-starter-kit/tree/feature/redux/ with Auth0 example
MIT License
2 stars 3 forks source link

Understanding and planning node.js and PHP servers #5

Closed cmosguy closed 8 years ago

cmosguy commented 8 years ago

@langpavel, I just realized that I need to understand how to dispatch all the setLocal, setMe functions from the client.

There are two options for the serverr setup:

  1. OPTION #1 - using Node.js to server the index.html, and it somehow injects the store into the client. I do not understand how this works, can you please explain to me in our next session? Please prepare an explanation so this goes smoothly. In addition, my API server is PHP serving the API through json web tokens.
  2. OPTION #2 - this uses the PHP as the backend server for index.html and the JWT API PHP.

image

I was planning on doing OPTION 2, but the code relies on server.js.

Here is a snippet from the code:

 const store = configureStore({}, {
      cookie: req.headers.cookie,
    });

    store.dispatch(setRuntimeVariable({
      name: 'initialNow',
      value: Date.now(),
    }));

    store.dispatch(setRuntimeVariable({
      name: 'availableLocales',
      value: locales,
    }));

    await store.dispatch(setLocale({
      locale,
    }));

I also want to do a store.dispatch(setMe{}) to fetch my PHP servers API to get the "me" info. This is an example API from the server. I will use this to help me learn how to fetch other requests and objects from the server as well.

Is it possible to move the stuff from server.js so I can inject the store from my PHP server for OPTION #2?

langpavel commented 8 years ago

Hi. You can dispatch for example getUserInfo action on serer which can use isomorphic helper to make a XMLHttpRequest on client or HTTP request from server with JWT token. This way your app can be prerendered on server and client will smoothly mount on state.

cmosguy commented 8 years ago

Hi @langpavel so I did more of a my homework, it appears that I did not completely understand isomorphic web apps clearly. Since the components are rendered on the server, then assuming that the PHP serves the HTML is not going to happen. However, it will serve the API, which is basically OPTION #1 above.