Reactgo: Centralize Configurations

Created on 30 Nov 2016  路  8Comments  路  Source: reactGo/reactGo

Why

  • We have configurations files within:

    • app/config/app.js

    • server/config/appConfig.js

My proposal is to move all of these to config/app.js which will contain all the files. Eliminating confusion.

Most helpful comment

Update of what I've done so far:

https://github.com/reactGo/reactGo/compare/master...choonkending:centralize-config

  • Move app/config/app to config/
  • Move express, routes, passport in server/config out to individual files
  • Move remaining server/config/* to config/

Still need to merge config/app and config/appConfig

All 8 comments

Good idea. I hate duplication, too.

Update of what I've done so far:

https://github.com/reactGo/reactGo/compare/master...choonkending:centralize-config

  • Move app/config/app to config/
  • Move express, routes, passport in server/config out to individual files
  • Move remaining server/config/* to config/

Still need to merge config/app and config/appConfig

Having a bit of trouble babel-ifying some of the directories outside of server in production.

I think we should run webpack through server/index.js instead of server.jsx.

That way we can remove the need of running out server/ folder through babel on server start.

There's no reason not to use webpack for node/io.js code, and let me tell you, it's amazing. I'm going to show you, in a few posts, how to do it. This is part one.

Basically http://jlongster.com/Backend-Apps-with-Webpack--Part-I

Well this exercise is going to take me a while

Time to shave some yaks

image

I'm gonna do #746 first because that's what you do when you shave a yak

What i actually did in my project was the following:
I used node-config as my configuration manager because i had several environments and wanted the ability to control all of them in 1 place (both server and client side).
So i've create a folder config at the root directory (like you did) and places all the config files there.
In the server side (the express app) i can just use those files and the config module as usual because, well its there.
On the client side its a little more tricky. Because my project is using a remote API server, i had to pass the configuration down to the browser side of the app.
For this, once i loaded the config, i placed it at the express.appLocals variable so that every request that comes to the server would have this config available to it.
After that, when creating the redux store, i added this configuration to the store and then i was able to access it from the client side as well (cool =] )
To sum up:

  • Used node-config module to load the configuration for the project
  • Once express loads up, i put the client configuration on the app.locals variable that express exposes
  • Once a request arrives to the server i bootstrap the redux store with that config from the app.locals of express
  • Access the config from the redux store where needed (for example to get the URL of the remote API server)

Given that https://github.com/reactGo/reactGo/issues/794 has been raised, I'm closing this and move to Done

Was this page helpful?
0 / 5 - 0 ratings

Related issues

newasmod picture newasmod  路  4Comments

ZeroCho picture ZeroCho  路  8Comments

kenjim83 picture kenjim83  路  8Comments

choonkending picture choonkending  路  9Comments

azamatsmith picture azamatsmith  路  6Comments