reap
reap copied to clipboard
React + Express + Alt + Postgres (and a bit of mongo)
REAP
| React + Express + Alt + Postgresql | ... and Mongo
Boilerplate for React application with webpack using alt's Flux running on a node express server with sequelize to connect to postgresl and mongoose for mongoDB. That was a mouthful.
This is based off my original React+Webpack+Node. Having sequelize with postgresql might seem like a small extra dependency, but I did not wish to overcomplicate the mission of that repo (plus it would be hard for beginners to deal with an extra database).
Why postgresql?
I am all for using MongoDB for a boilerplate (which is why I am leaving it in). But being a postgres fanboy myself, this repo appeared!
Demo site:
https://react-express-alt-postgres.herokuapp.com/
Features:
- Isomorphic Flux using:
- alt as my Flux implementation
- iso to help with bootstrapping data for isomorphic Flux
- react-router
- Stores storing data using ImmutableJS data structures
- Webpack config file
- Express server
- Mongoose for MongoDB
- Sequelize for Postgresql
- Includes a Procfile to enable deployment to Heroku.
Why alt?
Having isomorphic React was one of my key criteria when choosing a Flux library, which helped narrow down the scope of libraries.
I found alt's implementation to be clean and simple, and like the option of allowing us to create alt instances or using singletons (and flushing the stores). I also like the direction in which alt is heading.
Mission
The aim of this repo is to incorporate the best practices to building a non-trivial apps with Reactjs and Node. I am working to document this repo extensively so it would be easy for both beginners and experts to begin dev-ing on it without pulling your hair out.
Instructions
npm installnpm startto run locally
Bundling with webpack
npm run buildrunswebpackwill run configurations within webpack.config.js.npm run watchrunswebpack --watchto watch and recompile for changes.
Where do you compile your scss?
We use ExtractTextPlugin to extract compiled css in our webpack config file
Setting up your Database
Postgresql
npm install --save sequelizenpm install --save pg pg-hstore
MongoDB
brew updatebrew install mongodbmongod(Make sure you have the permissions to the directory /data/db)
Note:
For local dev, you have to create your database locally, by following either steps:
createdb ReactWebpackNodeon command line, read more here- Creating it manually using pgadmin
- psql magic
Deploying to Heroku
heroku createheroku app:rename newnameif you need togit push heroku master
Note: If you are working from a different machine and get heroku does not appear to be a remote repository message, be sure to run git remote add heroku [email protected]:appname.git.
4. heroku open to open the link
5. If you wish to have a database setup on Heroku, remember to use the commands below for the following databases:
MongoDB:
heroku addons:add mongohqorheroku addons:add mongolabPostgresql:heroku addons:create heroku-postgresql
Note: For Google Auth, read Setting up Google Authentication below
Deploying to Digital Ocean
- Create a Droplet
- Follow this or this tutorial to set up nodejs
- Follow this tutorial to install mongodb
- git clone this repo
npm installsudo npm install pm2 -gpm2 start server/index.jspm2 startup ubuntusudo env PATH=$PATH:/usr/local/bin pm2 startup ubuntu -u sammy
Component Hierarchy
- app.js
- App.react
- NavigationBar.react
- RouteHandler - Vote.react - EntryBox.react - MainSection.react - Scoreboard.react - Login.react - Logout.react - About.react - Dashboard.react - PriorityNotes.react - Profile.react
- App.react
IsomorphicRouterRenderer
This is a modified version of alt's IsomorphicRenderer. I wished to use webpack to build my server and client side code, but wanted to easily bootstrap data into the stores, and render the correct component using react-router. This takes into account the fact that we're using a singleton store and flushing it everytime (as opposed to creating an instance everytime).
Questions:
- Google Authentication does not work locally or on heroku!
Setting up Google Authentication
- Follow these steps from Google to create your API keys on Google Developers Console
- Under APIs & Auth, Copy your Client ID and Client Secret
Dev
For Google Auth to work locally, you need to do the following in your terminal before starting the server:
export GOOGLE_CLIENTID=YOUR_CLIENTID
export GOOGLE_SECRET=YOUR_SECRET
Heroku
Fret not! Heroku's covered this pretty well.
-
heroku config:set GOOGLE_CLIENTID=YOUR_CLIENTID -
heroku config:set GOOGLE_SECRET=YOUR_SECRET -
heroku config:set GOOGLE_CALLBACK=YOUR_CALLBACK
- Postgresql does not work locally. It throws a role "root" does not exist error!
You might not have sufficient permissions for the database. A quick way to fix this is to:
export PGUSER=whoami`` (secrets.js defaults to process.env.PGUSER)
Todo:
- My efforts will be focused primarily on React+Webpack+Node. However, so if you have any questions/issues with this repo, feel free to create an issue!
How to Contribute:
- As this repo is still in its baby stages, any suggestions/improvements/bugs can be in the form of Pull Requests, or creating an issue.
Credits to webpack-server-side-example, example-app, flux-examples, node-express-mongo-demo, hackathon-starter, web-starter-kit, awesome material-ui, alt and iso, and React+Webpack+Node
License
MIT