This project provides a starting point for building a React or OAuth application.
rails new my_app -m https://raw.githubusercontent.com/atomicjolt/react_starter_app/master/template.rb
Foreman makes it simple to startup all the services required to run the application in development mode. To start the application using foreman simply run:
$ foreman start -f Procfile.dev
Make sure you have the latest version of Foreman installed.
Foreman will automatically find and read the .env file.
If you need to run services individually or just don't like Foreman you can run each service seperately:
$ rails server
$ cd client && nodemon webpack.hot.js
$ ngrok --subdomain master_assets --log stdout 8080
$ ngrok --subdomain reactstarterapp --log stdout 3000
Rename .env.example
to .env
and configure it to your liking.
Note: the App and Assets subdomains must be different.
- Open application.rb and change
ReactStarterApp
to the name you choose. - Do a global search and replace for
react_starter_app
and change it to the name you choose. - Do a global search and replace for
reactstarterapp
(use only letters or numbers for this name. Special characters like '_' will result in errors).
Rename config/secrets.example.yml
to config/secrets.yml
. Open the file and change each entry to values that are relevant for your application.
This file should not be committed to your repository.
You will need to request a Key ID and Secret from the desired provider. You will also need to setup a default account and provide that account's "code" for the "application_code" entry in secrets.yml. See the seeds section below for information on setting up the default account.
This application requires:
- Ruby
- Rails
- PostGreSQL
Learn more about Installing Rails.
To test your application with an OAuth provider you will need to provide a public SSL url. The simpliest way to do this is to use ngrok which can be downloaded from ngrok.
Running 'ngrok --subdomain reactstarterapp --log stdout 3000' will create a tunnel. You will access your application using the ngrok url:
https://reactstarterapp.ngrok.io
Packs CommonJs/AMD modules for the browser.
$ npm install -g webpack
$ cd client && webpack
To get started run:
$ npm install
npm-shrinkwrap is used to lock specific versions. npm-shrinkwrap.json is included in the project. To verify your package.json & node_modules tree are in sync run:
$ npm shrinkwrap
To find outdated modules run:
$ npm outdated
Packages must be updated manually. For example:
$ npm update lodash
After updating be sure to run shrinkwrap again:
$ npm shrinkwrap
The React Starter App uses React. During development run the React Hot Loader.
Open db/seeds.rb and configuration a default account for development and production. Here's a summary of the values and their purpose:
- code: Uniquely identifies the account. This is used for the subdomain when running applications on a single domain.
- domain: Custom domain name.
- name: Name the account anything you'd like.
Once you've setup your seeds file run it to setup database defaults:
$ rake db:setup
or
$ rake db:create
$ rake db:schema:load
$ rake db:seed
Visit the provider (Facebook, Twitter, Google, etc) to obtain an OAuth key and secret. Most of the fields will be specific to your organization.
The Oauth2 Redirect URI and Icon URL will be as follows below. Be sure to replace reactstarterapp.ngrok.io
with your domain.
You will need an ID and secret for development and for production. The
development URI will use ngrok while the production URI will use your domain.
Oauth2 Redirect URI: https://reactstarterapp.ngrok.io/auth/[provider]/callback
Icon URL: https://reactstarterapp.ngrok.io/oauth_icon.png
Once your request is approved you will receive a Key and Secret. Add these credentials to the config/secrets.yml
.
Make sure you have signed up for a heroku account Heroku. Then follow the instructions provided by Heroku to create your application.
Push secrets to production:
$ rake heroku:secrets RAILS_ENV=production
Deploy to Heroku:
$ git push heroku master
By default config/unicorn.rb
is setup to deploy to Heroku. Open that file, comment out the Heroku section and uncomment the other configuration to setup unicorn for deployment to another service like AWS.
Atomic Jolt has built a number of applications based on this source.
This application uses PostgreSQL with ActiveRecord.
You may need to install chromedriver if you haven't already.
$ brew install chromedriver
To run tests:
$ rake spec