├── .babelrc ├── .editorconfig ├── .eslintignore ├── .eslintrc ├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── api ├── __tests__ │ └── api-account-test.js ├── api.js ├── models │ └── index.js └── utils │ ├── passportConfig.js │ └── passportRoutes.js ├── app.json ├── bin ├── api.js └── server.js ├── circle.yml ├── docs ├── AddingAPage │ ├── AddingAPage.md │ ├── edit_app.png │ ├── edit_app2.png │ ├── edit_index.png │ ├── edit_route1.png │ ├── edit_route2.png │ ├── ick_about.png │ ├── ick_alias.png │ ├── new_hello.png │ └── show_hello.png ├── AddingToHomePage │ ├── AddingToHomePage.md │ ├── add_home.png │ ├── find_home1.png │ ├── find_home2.png │ ├── find_home3.png │ ├── find_home4.png │ └── hello_rendered.png ├── ApiConfig.md ├── Ducks.md ├── ExploringTheDemoApp │ ├── ExploringTheDemoApp.md │ ├── about_markup.png │ ├── frontpage.png │ ├── frontpage_markup.png │ ├── survey_markup.png │ └── widgets_markup.png ├── InlineStyles.md └── InstallingTheKit │ ├── InstallingTheKit.md │ ├── dependencies.png │ ├── git_clone.png │ ├── npm_run.png │ ├── port3000.png │ ├── run_dev1.png │ ├── run_dev2.png │ └── start_npm.png ├── karma.conf.js ├── package.json ├── server.babel.js ├── src ├── client.js ├── components │ ├── CounterButton │ │ └── CounterButton.js │ ├── GithubButton │ │ └── GithubButton.js │ ├── __tests__ │ │ └── InfoBar-test.js │ └── index.js ├── config.js ├── containers │ ├── About │ │ ├── About.js │ │ └── kitten.jpg │ ├── App │ │ ├── App.js │ │ └── App.scss │ ├── DevTools │ │ └── DevTools.js │ ├── Home │ │ ├── Home.js │ │ ├── Home.scss │ │ └── logo.png │ ├── Login │ │ ├── Login.js │ │ └── Login.scss │ ├── LoginSuccess │ │ └── LoginSuccess.js │ ├── NotFound │ │ └── NotFound.js │ ├── Signup │ │ ├── Signup.js │ │ └── Signup.scss │ └── index.js ├── helpers │ ├── ApiClient.js │ └── Html.js ├── redux │ ├── create.js │ ├── middleware │ │ └── clientMiddleware.js │ └── modules │ │ ├── auth.js │ │ ├── counter.js │ │ └── reducer.js ├── routes.js ├── server.js ├── theme │ ├── bootstrap.config.js │ ├── bootstrap.config.prod.js │ ├── bootstrap.overrides.scss │ ├── font-awesome.config.js │ ├── font-awesome.config.less │ ├── font-awesome.config.prod.js │ └── variables.scss └── utils │ └── validation.js ├── static ├── favicon.ico ├── favicon.png └── logo.jpg ├── tests.webpack.js └── webpack ├── dev.config.js ├── prod.config.js ├── webpack-dev-server.js └── webpack-isomorphic-tools.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["react", "es2015", "stage-0"], 3 | 4 | "plugins": [ 5 | "transform-runtime", 6 | "add-module-exports", 7 | "transform-decorators-legacy", 8 | "transform-react-display-name" 9 | ], 10 | 11 | "env": { 12 | "development": { 13 | "plugins": [ 14 | "typecheck", 15 | ["react-transform", { 16 | "transforms": [{ 17 | "transform": "react-transform-catch-errors", 18 | "imports": ["react", "redbox-react"] 19 | } 20 | ] 21 | }] 22 | ] 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | indent_style = space 3 | end_of_line = lf 4 | indent_size = 2 5 | charset = utf-8 6 | trim_trailing_whitespace = true 7 | 8 | [*.md] 9 | max_line_length = 0 10 | trim_trailing_whitespace = false 11 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | webpack/* 2 | karma.conf.js 3 | tests.webpack.js 4 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { "extends": "eslint-config-airbnb", 2 | "env": { 3 | "browser": true, 4 | "node": true, 5 | "mocha": true 6 | }, 7 | "rules": { 8 | "react/no-multi-comp": 0, 9 | "import/default": 0, 10 | "import/no-duplicates": 0, 11 | "import/named": 0, 12 | "import/namespace": 0, 13 | "import/no-unresolved": 0, 14 | "import/no-named-as-default": 2, 15 | "comma-dangle": 0, // not sure why airbnb turned this on. gross! 16 | "indent": [2, 2, {"SwitchCase": 1}], 17 | "no-console": 0, 18 | "no-alert": 0 19 | }, 20 | "plugins": [ 21 | "react", "import" 22 | ], 23 | "settings": { 24 | "import/parser": "babel-eslint", 25 | "import/resolve": { 26 | moduleDirectory: ["node_modules", "src"] 27 | } 28 | }, 29 | "globals": { 30 | "__DEVELOPMENT__": true, 31 | "__CLIENT__": true, 32 | "__SERVER__": true, 33 | "__DISABLE_SSR__": true, 34 | "__DEVTOOLS__": true, 35 | "socket": true, 36 | "webpackIsomorphicTools": true 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | node_modules/ 3 | dist/ 4 | *.iml 5 | webpack-assets.json 6 | webpack-stats.json 7 | npm-debug.log 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - "0.12" 5 | - "4.0" 6 | - "4" 7 | - "5" 8 | - "stable" 9 | 10 | sudo: false 11 | 12 | before_script: 13 | - export DISPLAY=:99.0 14 | - sh -e /etc/init.d/xvfb start 15 | 16 | script: 17 | - npm run lint 18 | - npm test 19 | - npm run test-node 20 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Some basic conventions for contributing to this project. 4 | 5 | ### General 6 | 7 | Please make sure that there aren't existing pull requests attempting to address the issue mentioned. Likewise, please check for issues related to update, as someone else may be working on the issue in a branch or fork. 8 | 9 | * Non-trivial changes should be discussed in an issue first 10 | * Develop in a topic branch, not master 11 | * Squash your commits 12 | 13 | ### Linting 14 | 15 | Please check your code using `npm run lint` before submitting your pull requests, as the CI build will fail if `eslint` fails. 16 | 17 | ### Commit Message Format 18 | 19 | Each commit message should include a **type**, a **scope** and a **subject**: 20 | 21 | ``` 22 | (): 23 | ``` 24 | 25 | Lines should not exceed 100 characters. This allows the message to be easier to read on github as well as in various git tools and produces a nice, neat commit log ie: 26 | 27 | ``` 28 | #459 refactor(utils): create url mapper utility function 29 | #463 chore(webpack): update to isomorphic tools v2 30 | #494 fix(babel): correct dependencies and polyfills 31 | #510 feat(app): add react-bootstrap responsive navbar 32 | ``` 33 | 34 | #### Type 35 | 36 | Must be one of the following: 37 | 38 | * **feat**: A new feature 39 | * **fix**: A bug fix 40 | * **docs**: Documentation only changes 41 | * **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing 42 | semi-colons, etc) 43 | * **refactor**: A code change that neither fixes a bug or adds a feature 44 | * **test**: Adding missing tests 45 | * **chore**: Changes to the build process or auxiliary tools and libraries such as documentation 46 | generation 47 | 48 | #### Scope 49 | 50 | The scope could be anything specifying place of the commit change. For example `webpack`, 51 | `helpers`, `api` etc... 52 | 53 | #### Subject 54 | 55 | The subject contains succinct description of the change: 56 | 57 | * use the imperative, present tense: "change" not "changed" nor "changes" 58 | * don't capitalize first letter 59 | * no dot (.) at the end 60 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Erik Rasmussen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Redux Universal Hot Example 2 | 3 | [![build status](https://img.shields.io/travis/erikras/react-redux-universal-hot-example/master.svg?style=flat-square)](https://travis-ci.org/erikras/react-redux-universal-hot-example) 4 | [![Dependency Status](https://david-dm.org/erikras/react-redux-universal-hot-example.svg?style=flat-square)](https://david-dm.org/erikras/react-redux-universal-hot-example) 5 | [![devDependency Status](https://david-dm.org/erikras/react-redux-universal-hot-example/dev-status.svg?style=flat-square)](https://david-dm.org/erikras/react-redux-universal-hot-example#info=devDependencies) 6 | [![react-redux-universal channel on discord](https://img.shields.io/badge/discord-react--redux--universal%40reactiflux-brightgreen.svg?style=flat-square)](https://discord.gg/0ZcbPKXt5bZZb1Ko) 7 | [![Demo on Heroku](https://img.shields.io/badge/demo-heroku-brightgreen.svg?style=flat-square)](https://react-redux.herokuapp.com) 8 | [![PayPal donate button](https://img.shields.io/badge/donate-paypal-brightgreen.svg?style=flat-square)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=E2LK57ZQ9YRMN) 9 | 10 | --- 11 | 12 | ## About 13 | 14 | This is a starter boilerplate app I've put together using the following technologies: 15 | 16 | * ~~Isomorphic~~ [Universal](https://medium.com/@mjackson/universal-javascript-4761051b7ae9) rendering 17 | * Both client and server make calls to load data from separate API server 18 | * [React](https://github.com/facebook/react) 19 | * [React Router](https://github.com/rackt/react-router) 20 | * [Express](http://expressjs.com) 21 | * [Babel](http://babeljs.io) for ES6 and ES7 magic 22 | * [Webpack](http://webpack.github.io) for bundling 23 | * [Webpack Dev Middleware](http://webpack.github.io/docs/webpack-dev-middleware.html) 24 | * [Webpack Hot Middleware](https://github.com/glenjamin/webpack-hot-middleware) 25 | * [Redux](https://github.com/rackt/redux)'s futuristic [Flux](https://facebook.github.io/react/blog/2014/05/06/flux.html) implementation 26 | * [Redux Dev Tools](https://github.com/gaearon/redux-devtools) for next generation DX (developer experience). Watch [Dan Abramov's talk](https://www.youtube.com/watch?v=xsSnOQynTHs). 27 | * [React Router Redux](https://github.com/reactjs/react-router-redux) Redux/React Router bindings. 28 | * [ESLint](http://eslint.org) to maintain a consistent code style 29 | * [redux-form](https://github.com/erikras/redux-form) to manage form state in Redux 30 | * [lru-memoize](https://github.com/erikras/lru-memoize) to speed up form validation 31 | * [multireducer](https://github.com/erikras/multireducer) to combine single reducers into one key-based reducer 32 | * [style-loader](https://github.com/webpack/style-loader), [sass-loader](https://github.com/jtangelder/sass-loader) and [less-loader](https://github.com/webpack/less-loader) to allow import of stylesheets in plain css, sass and less, 33 | * [bootstrap-sass-loader](https://github.com/shakacode/bootstrap-sass-loader) and [font-awesome-webpack](https://github.com/gowravshekar/font-awesome-webpack) to customize Bootstrap and FontAwesome 34 | * [react-helmet](https://github.com/nfl/react-helmet) to manage title and meta tag information on both server and client 35 | * [webpack-isomorphic-tools](https://github.com/halt-hammerzeit/webpack-isomorphic-tools) to allow require() work for statics both on client and server 36 | * [mocha](https://mochajs.org/) to allow writing unit tests for the project. 37 | 38 | I cobbled this together from a wide variety of similar "starter" repositories. As I post this in June 2015, all of these libraries are right at the bleeding edge of web development. They may fall out of fashion as quickly as they have come into it, but I personally believe that this stack is the future of web development and will survive for several years. I'm building my new projects like this, and I recommend that you do, too. 39 | 40 | ## Installation 41 | 42 | ```bash 43 | npm install 44 | ``` 45 | 46 | ## Running Dev Server 47 | 48 | ```bash 49 | npm run dev 50 | ``` 51 | 52 | The first time it may take a little while to generate the first `webpack-assets.json` and complain with a few dozen `[webpack-isomorphic-tools] (waiting for the first Webpack build to finish)` printouts, but be patient. Give it 30 seconds. 53 | 54 | ### Using Redux DevTools 55 | 56 | [Redux Devtools](https://github.com/gaearon/redux-devtools) are enabled by default in development. 57 | 58 | - CTRL+H Toggle DevTools Dock 59 | - CTRL+Q Move DevTools Dock Position 60 | - see [redux-devtools-dock-monitor](https://github.com/gaearon/redux-devtools-dock-monitor) for more detailed information. 61 | 62 | If you have the 63 | [Redux DevTools chrome extension](https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd) installed it will automatically be used on the client-side instead. 64 | 65 | If you want to disable the dev tools during development, set `__DEVTOOLS__` to `false` in `/webpack/dev.config.js`. 66 | DevTools are not enabled during production. 67 | 68 | ## Building and Running Production Server 69 | 70 | ```bash 71 | npm run build 72 | npm run start 73 | ``` 74 | 75 | ## Demo 76 | 77 | A demonstration of this app can be seen [running on heroku](https://react-redux.herokuapp.com), which is a deployment of the [heroku branch](https://github.com/erikras/react-redux-universal-hot-example/tree/heroku). 78 | 79 | ## Documentation 80 | 81 | * [Exploring the Demo App](docs/ExploringTheDemoApp/ExploringTheDemoApp.md) is a guide that can be used before you install the kit. 82 | * [Installing the Kit](docs/InstallingTheKit/InstallingTheKit.md) guides you through installation and running the development server locally. 83 | * [Adding Text to the Home Page](docs/AddingToHomePage/AddingToHomePage.md) guides you through adding "Hello, World!" to the home page. 84 | * [Adding A Page](docs/AddingAPage/AddingAPage.md) guides you through adding a new page. 85 | * [React Tutorial - Converting Reflux to Redux](http://engineering.wework.com/process/2015/10/01/react-reflux-to-redux/), by Matt Star 86 | If you are the kind of person that learns best by following along a tutorial, I can recommend Matt Star's overview and examples. 87 | 88 | 89 | ## Explanation 90 | 91 | What initially gets run is `bin/server.js`, which does little more than enable ES6 and ES7 awesomeness in the 92 | server-side node code. It then initiates `server.js`. In `server.js` we proxy any requests to `/api/*` to the 93 | [API server](#api-server), running at `localhost:3030`. All the data fetching calls from the client go to `/api/*`. 94 | Aside from serving the favicon and static content from `/static`, the only thing `server.js` does is initiate delegate 95 | rendering to `react-router`. At the bottom of `server.js`, we listen to port `3000` and initiate the API server. 96 | 97 | #### Routing and HTML return 98 | 99 | The primary section of `server.js` generates an HTML page with the contents returned by `react-router`. First we instantiate an `ApiClient`, a facade that both server and client code use to talk to the API server. On the server side, `ApiClient` is given the request object so that it can pass along the session cookie to the API server to maintain session state. We pass this API client facade to the `redux` middleware so that the action creators have access to it. 100 | 101 | Then we perform [server-side data fetching](#server-side-data-fetching), wait for the data to be loaded, and render the page with the now-fully-loaded `redux` state. 102 | 103 | The last interesting bit of the main routing section of `server.js` is that we swap in the hashed script and css from the `webpack-assets.json` that the Webpack Dev Server – or the Webpack build process on production – has spit out on its last run. You won't have to deal with `webpack-assets.json` manually because [webpack-isomorphic-tools](https://github.com/halt-hammerzeit/webpack-isomorphic-tools) take care of that. 104 | 105 | We also spit out the `redux` state into a global `window.__data` variable in the webpage to be loaded by the client-side `redux` code. 106 | 107 | #### Server-side Data Fetching 108 | 109 | We ask `react-router` for a list of all the routes that match the current request and we check to see if any of the matched routes has a static `fetchData()` function. If it does, we pass the redux dispatcher to it and collect the promises returned. Those promises will be resolved when each matching route has loaded its necessary data from the API server. 110 | 111 | #### Client Side 112 | 113 | The client side entry point is reasonably named `client.js`. All it does is load the routes, initiate `react-router`, rehydrate the redux state from the `window.__data` passed in from the server, and render the page over top of the server-rendered DOM. This makes React enable all its event listeners without having to re-render the DOM. 114 | 115 | #### Redux Middleware 116 | 117 | The middleware, [`clientMiddleware.js`](https://github.com/erikras/react-redux-universal-hot-example/blob/master/src/redux/middleware/clientMiddleware.js), serves two functions: 118 | 119 | 1. To allow the action creators access to the client API facade. Remember this is the same on both the client and the server, and cannot simply be `import`ed because it holds the cookie needed to maintain session on server-to-server requests. 120 | 2. To allow some actions to pass a "promise generator", a function that takes the API client and returns a promise. Such actions require three action types, the `REQUEST` action that initiates the data loading, and a `SUCCESS` and `FAILURE` action that will be fired depending on the result of the promise. There are other ways to accomplish this, some discussed [here](https://github.com/rackt/redux/issues/99), which you may prefer, but to the author of this example, the middleware way feels cleanest. 121 | 122 | #### Redux Modules... *What the Duck*? 123 | 124 | The `src/redux/modules` folder contains "modules" to help 125 | isolate concerns within a Redux application (aka [Ducks](https://github.com/erikras/ducks-modular-redux), a Redux Style Proposal that I came up with). I encourage you to read the 126 | [Ducks Docs](https://github.com/erikras/ducks-modular-redux) and provide feedback. 127 | 128 | #### API Server 129 | 130 | This is where the meat of your server-side application goes. It doesn't have to be implemented in Node or Express at all. This is where you connect to your database and provide authentication and session management. In this example, it's just spitting out some json with the current time stamp. 131 | 132 | #### Getting data and actions into components 133 | 134 | To understand how the data and action bindings get into the components – there's only one, `InfoBar`, in this example – I'm going to refer to you to the [Redux](https://github.com/gaearon/redux) library. The only innovation I've made is to package the component and its wrapper in the same js file. This is to encapsulate the fact that the component is bound to the `redux` actions and state. The component using `InfoBar` needn't know or care if `InfoBar` uses the `redux` data or not. 135 | 136 | #### Images 137 | 138 | Now it's possible to render the image both on client and server. Please refer to issue [#39](https://github.com/erikras/react-redux-universal-hot-example/issues/39) for more detail discussion, the usage would be like below (super easy): 139 | 140 | ```javascript 141 | let logoImage = require('./logo.png'); 142 | ``` 143 | 144 | #### Styles 145 | 146 | This project uses [local styles](https://medium.com/seek-ui-engineering/the-end-of-global-css-90d2a4a06284) using [css-loader](https://github.com/webpack/css-loader). The way it works is that you import your stylesheet at the top of the `render()` function in your React Component, and then you use the classnames returned from that import. Like so: 147 | 148 | ```javascript 149 | render() { 150 | const styles = require('./App.scss'); 151 | ... 152 | ``` 153 | 154 | Then you set the `className` of your element to match one of the CSS classes in your SCSS file, and you're good to go! 155 | 156 | ```jsx 157 |
...
158 | ``` 159 | 160 | #### Alternative to Local Styles 161 | 162 | If you'd like to use plain inline styles this is possible with a few modifications to your webpack configuration. 163 | 164 | **1. Configure Isomorphic Tools to Accept CSS** 165 | 166 | In `webpack-isomorphic-tools.js` add **css** to the list of style module extensions 167 | 168 | ```javascript 169 | style_modules: { 170 | extensions: ['less','scss','css'], 171 | ``` 172 | 173 | **2. Add a CSS loader to webpack dev config** 174 | 175 | In `dev.config.js` modify **module loaders** to include a test and loader for css 176 | 177 | ```javascript 178 | module: { 179 | loaders: [ 180 | { test: /\.css$/, loader: 'style-loader!css-loader'}, 181 | ``` 182 | 183 | **3. Add a CSS loader to the webpack prod config** 184 | 185 | You must use the **ExtractTextPlugin** in this loader. In `prod.config.js` modify **module loaders** to include a test and loader for css 186 | 187 | ```javascript 188 | module: { 189 | loaders: [ 190 | { test: /\.css$/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader')}, 191 | ``` 192 | 193 | **Now you may simply omit assigning the `required` stylesheet to a variable and keep it at the top of your `render()` function.** 194 | 195 | ```javascript 196 | render() { 197 | require('./App.css'); 198 | require('aModule/dist/style.css'); 199 | ... 200 | ``` 201 | 202 | **NOTE** In order to use this method with **scss or less** files one more modification must be made. In both `dev.config.js` and `prod.config.js` in the loaders for less and scss files remove 203 | 204 | 1. `modules` 205 | 2. `localIdentName...` 206 | 207 | Before: 208 | ```javascript 209 | { test: /\.less$/, loader: 'style!css?modules&importLoaders=2&sourceMap&localIdentName=[local]___[hash:base64:5]!autoprefixer?browsers=last 2 version!less?outputStyle=expanded&sourceMap' }, 210 | ``` 211 | After: 212 | ```javascript 213 | { test: /\.less$/, loader: 'style!css?importLoaders=2&sourceMap!autoprefixer?browsers=last 2 version!less?outputStyle=expanded&sourceMap' }, 214 | ``` 215 | 216 | After this modification to both loaders you will be able to use scss and less files in the same way as css files. 217 | 218 | #### Unit Tests 219 | 220 | The project uses [Mocha](https://mochajs.org/) to run your unit tests, it uses [Karma](http://karma-runner.github.io/0.13/index.html) as the test runner, it enables the feature that you are able to render your tests to the browser (e.g: Firefox, Chrome etc.), which means you are able to use the [Test Utilities](http://facebook.github.io/react/docs/test-utils.html) from Facebook api like `renderIntoDocument()`. 221 | 222 | To run the tests in the project, just simply run `npm test` if you have `Chrome` installed, it will be automatically launched as a test service for you. 223 | 224 | To keep watching your test suites that you are working on, just set `singleRun: false` in the `karma.conf.js` file. Please be sure set it to `true` if you are running `npm test` on a continuous integration server (travis-ci, etc). 225 | 226 | ## Deployment on Heroku 227 | 228 | To get this project to work on Heroku, you need to: 229 | 230 | 1. Remove the `"PORT": 8080` line from the `betterScripts` / `start-prod` section of `package.json`. 231 | 2. `heroku config:set NODE_ENV=production` 232 | 3. `heroku config:set NODE_PATH=./src` 233 | 4. `heroku config:set NPM_CONFIG_PRODUCTION=false` 234 | * This is to enable webpack to run the build on deploy. 235 | 236 | The first deploy might take a while, but after that your `node_modules` dir should be cached. 237 | 238 | ## FAQ 239 | 240 | This project moves fast and has an active community, so if you have a question that is not answered below please visit our [Discord channel](https://discord.gg/0ZcbPKXt5bZZb1Ko) or file an issue. 241 | 242 | 243 | ## Roadmap 244 | 245 | Although this isn't a library, we recently started versioning to make it easier to track breaking changes and emerging best practices. 246 | 247 | * [Inline Styles](docs/InlineStyles.md) - CSS is dead 248 | 249 | ## Contributing 250 | 251 | I am more than happy to accept external contributions to the project in the form of feedback, bug reports and even better - pull requests :) 252 | 253 | If you would like to submit a pull request, please make an effort to follow the guide in [CONTRIBUTING.md](CONTRIBUTING.md). 254 | 255 | --- 256 | Thanks for checking this out. 257 | 258 | – Erik Rasmussen, [@erikras](https://twitter.com/erikras) 259 | -------------------------------------------------------------------------------- /api/__tests__/api-account-test.js: -------------------------------------------------------------------------------- 1 | import supertest from 'supertest'; 2 | import {should} from 'should'; 3 | 4 | // https://codeforgeek.com/2015/07/unit-testing-nodejs-application-using-mocha/ 5 | // npm run dev (on a separate tab, then) 6 | // npm run test-node 7 | var server = supertest.agent("http://localhost:3030"); 8 | 9 | describe('Simple api account test', () => { 10 | it('should 404 on root route', (done) => { 11 | server 12 | .get('/') 13 | .end((err, res) => { 14 | res.status.should.equal(404); 15 | done(); 16 | }); 17 | }); 18 | 19 | it('should be able to do a signup', (done) => { 20 | server 21 | .post('/signup') 22 | .send({email:'asdf@asdf.com', password: 'asdf'}) 23 | .end((err, res) => { 24 | res.status.should.equal(200); 25 | done(); 26 | }); 27 | }); 28 | 29 | it('should be authenticated', (done) => { 30 | server 31 | .get('/me') 32 | .end((err, res) => { 33 | console.log(res.body); 34 | done(); 35 | }); 36 | }); 37 | 38 | it('should be able to do a login', (done) => { 39 | server 40 | .post('/login') 41 | .send({email:'asdf@asdf.com', password: 'asdf'}) 42 | .end((err, res) => { 43 | res.status.should.equal(200); 44 | done(); 45 | }); 46 | }); 47 | 48 | }); 49 | 50 | 51 | -------------------------------------------------------------------------------- /api/api.js: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import session from 'express-session'; 3 | import bodyParser from 'body-parser'; 4 | import cookieParser from 'cookie-parser'; 5 | import config from '../src/config'; 6 | import http from 'http'; 7 | import SocketIo from 'socket.io'; 8 | import { createSequelize, User } from './models/index'; 9 | import passport from 'passport'; 10 | import morgan from 'morgan'; 11 | import connectSessionSequelize from 'connect-session-sequelize'; 12 | import configPassport from './utils/passportConfig'; 13 | import passportRoutes from './utils/passportRoutes'; 14 | 15 | var SequelizeStore = connectSessionSequelize(session.Store); 16 | 17 | const app = express(); 18 | 19 | const server = new http.Server(app); 20 | 21 | //const io = new SocketIo(server); 22 | //io.path('/ws'); 23 | 24 | app.locals.sequelize = createSequelize(); 25 | 26 | app.use(session({ 27 | secret: 'somesecret', 28 | store: new SequelizeStore({ db: app.locals.sequelize }), 29 | resave: false, 30 | saveUninitialized: false, 31 | cookie: { maxAge: 60000 } 32 | })); 33 | app.use(bodyParser.json()); 34 | app.use(morgan('dev')); 35 | app.use(passport.initialize()); 36 | app.use(passport.session()); 37 | configPassport(passport); 38 | passportRoutes(app, passport); 39 | 40 | const bufferSize = 100; 41 | const messageBuffer = new Array(bufferSize); 42 | let messageIndex = 0; 43 | 44 | if (config.apiPort) { 45 | const runnable = app.listen(config.apiPort, (err) => { 46 | if (err) { 47 | console.error(err); 48 | } 49 | console.info('----\n==> 🌎 API is running on port %s', config.apiPort); 50 | console.info('==> 💻 Send requests to http://%s:%s', config.apiHost, config.apiPort); 51 | }); 52 | 53 | /* 54 | * 55 | * HU: Disabling socket.io server for now 56 | * 57 | io.on('connection', (socket) => { 58 | socket.emit('news', {msg: `'Hello World!' from server`}); 59 | 60 | socket.on('history', () => { 61 | for (let index = 0; index < bufferSize; index++) { 62 | const msgNo = (messageIndex + index) % bufferSize; 63 | const msg = messageBuffer[msgNo]; 64 | if (msg) { 65 | socket.emit('msg', msg); 66 | } 67 | } 68 | }); 69 | 70 | socket.on('msg', (data) => { 71 | data.id = messageIndex; 72 | messageBuffer[messageIndex % bufferSize] = data; 73 | messageIndex++; 74 | io.emit('msg', data); 75 | }); 76 | }); 77 | io.listen(runnable); 78 | */ 79 | 80 | } else { 81 | console.error('==> ERROR: No PORT environment variable has been specified'); 82 | } 83 | -------------------------------------------------------------------------------- /api/models/index.js: -------------------------------------------------------------------------------- 1 | import Sequelize from 'sequelize'; 2 | import bcrypt from 'bcrypt-nodejs'; 3 | 4 | export function createSequelize() { 5 | 6 | var sequelize = new Sequelize('database', 'username', 'password', { 7 | host: 'localhost', 8 | dialect: 'sqlite', 9 | 10 | pool: { 11 | max: 5, 12 | min: 0, 13 | idle: 10000 14 | }, 15 | 16 | // SQLite only 17 | storage: './database.sqlite' 18 | }); 19 | 20 | initializeModels(sequelize); 21 | return sequelize; 22 | } 23 | 24 | export var User = null; 25 | 26 | function initializeModels(sequelize) { 27 | User = sequelize.define('user', { 28 | email: { 29 | type: Sequelize.STRING, 30 | unique: true, 31 | }, 32 | password: Sequelize.STRING, 33 | },{ 34 | classMethods: { 35 | generateHash: password => { 36 | return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null); 37 | } 38 | }, 39 | instanceMethods: { 40 | validPassword: function(password) { 41 | return bcrypt.compareSync(password, this.password); 42 | } 43 | } 44 | }); 45 | 46 | if(process.env.TEST_DATABASE){ 47 | sequelize.sync({force: true}); 48 | }else{ 49 | sequelize.sync(); 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /api/utils/passportConfig.js: -------------------------------------------------------------------------------- 1 | import passportLocal from 'passport-local'; 2 | import { User } from '../models/index'; 3 | 4 | var LocalStrategy = passportLocal.Strategy; 5 | 6 | export default function configPassport(passport) { 7 | passport.serializeUser( (user, done) => { 8 | done(null, user.id); 9 | return null; 10 | }); 11 | 12 | passport.deserializeUser( (id, done) => { 13 | User.findOne({ where: {id: id} }).then( (user) => { 14 | done(null, user); 15 | return null; 16 | }).catch((err) => { 17 | done(err, user); 18 | return null; 19 | }); 20 | }); 21 | 22 | passport.use('local-signup', new LocalStrategy({usernameField: 'email', passwordField: 'password', passReqToCallback: true}, (req, email, password, done) => { 23 | process.nextTick(() => { 24 | User.findOne({where: {email: email}}).then(user => { 25 | if(user){ 26 | return null; 27 | }else{ 28 | let newUser = User.build({ 29 | email: email, 30 | password: User.generateHash(password), 31 | }); 32 | return newUser.save(); 33 | } 34 | }).then(newUser => { 35 | done(null, newUser); 36 | return null; 37 | }).catch(err => { 38 | console.log(`Err ${err}`); 39 | done(err); 40 | return null; 41 | }); 42 | 43 | })})); 44 | 45 | passport.use('local-login', new LocalStrategy({usernameField:'email', passwordField:'password', passReqToCallback: true}, (req, email, password, done) => { 46 | User.findOne({where: {email: email}}).then(user => { 47 | if(!user){ 48 | done(null, false); 49 | return null; 50 | } 51 | 52 | if(!user.validPassword(password)){ 53 | done(null, false); 54 | return null; 55 | } 56 | 57 | done(null, user); 58 | return null; 59 | }).catch(err => { 60 | done(err); 61 | return null; 62 | }); 63 | 64 | })); 65 | 66 | } 67 | -------------------------------------------------------------------------------- /api/utils/passportRoutes.js: -------------------------------------------------------------------------------- 1 | export default function passportRoutes(app, passport) { 2 | app.post('/login', 3 | passport.authenticate('local-login'), 4 | (req, res) => { 5 | console.log(`User ${req.user.username} logged in`); 6 | res.json( 7 | { 8 | status: 'ok', 9 | user: { 10 | email: req.user.email 11 | } 12 | }); 13 | } 14 | ); 15 | 16 | app.post('/signup', 17 | passport.authenticate('local-signup'), 18 | (req, res) => { 19 | // req.user now contains the right user 20 | console.log(`User ${req.user.email} signed up`); 21 | res.json( 22 | { 23 | status: 'ok', 24 | user: { 25 | email: req.user.email 26 | } 27 | }); 28 | } 29 | ); 30 | 31 | app.get('/me', 32 | (req, res) => { 33 | console.log(`Me is ${req.user}`); 34 | if(!req.user){ 35 | res.json({user:null}); 36 | }else{ 37 | res.json( 38 | { 39 | user: { 40 | email: req.user.email 41 | } 42 | }); 43 | } 44 | }); 45 | 46 | app.get('/logout', 47 | (req, res) => { 48 | req.logout(); 49 | res.json({status: 'ok'}); 50 | } 51 | ); 52 | 53 | /* 54 | # Facebook login routes 55 | app.get '/auth/facebook', passport.authenticate 'facebook', æ scope: 'email' 56 | app.get '/auth/facebook/callback', passport.authenticate 'facebook', æ successRedirect : '/profile', failureRedirect : '/' å 57 | 58 | # Twitter login routes 59 | app.get '/auth/twitter', passport.authenticate 'twitter' 60 | app.get '/auth/twitter/callback', passport.authenticate 'twitter', æ successRedirect : '/profile', failureRedirect : '/' å 61 | 62 | # Google login routes 63 | app.get '/auth/google', passport.authenticate 'google', æ scope: Æ'profile', 'email'Åå 64 | app.get '/auth/google/callback', passport.authenticate 'google', æ successRedirect : '/profile', failureRedirect : '/' å 65 | */ 66 | 67 | } 68 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-redux-universal-hot-example", 3 | "description": "Example of an isomorphic (universal) webapp using react redux and hot reloading", 4 | "repository": "https://github.com/erikras/react-redux-universal-hot-example", 5 | "logo": "http://node-js-sample.herokuapp.com/node.svg", 6 | "keywords": [ 7 | "react", 8 | "isomorphic", 9 | "universal", 10 | "webpack", 11 | "express", 12 | "hot reloading", 13 | "react-hot-reloader", 14 | "redux", 15 | "starter", 16 | "boilerplate", 17 | "babel" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /bin/api.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | if (process.env.NODE_ENV !== 'production') { 3 | if (!require('piping')({ 4 | hook: true, 5 | ignore: /(\/\.|~$|\.json$)/i 6 | })) { 7 | return; 8 | } 9 | } 10 | require('../server.babel'); // babel registration (runtime transpilation for node) 11 | require('../api/api'); 12 | -------------------------------------------------------------------------------- /bin/server.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('../server.babel'); // babel registration (runtime transpilation for node) 3 | var path = require('path'); 4 | var rootDir = path.resolve(__dirname, '..'); 5 | /** 6 | * Define isomorphic constants. 7 | */ 8 | global.__CLIENT__ = false; 9 | global.__SERVER__ = true; 10 | global.__DISABLE_SSR__ = false; // <----- DISABLES SERVER SIDE RENDERING FOR ERROR DEBUGGING 11 | global.__DEVELOPMENT__ = process.env.NODE_ENV !== 'production'; 12 | 13 | if (__DEVELOPMENT__) { 14 | if (!require('piping')({ 15 | hook: true, 16 | ignore: /(\/\.|~$|\.json|\.scss$)/i 17 | })) { 18 | return; 19 | } 20 | } 21 | 22 | // https://github.com/halt-hammerzeit/webpack-isomorphic-tools 23 | var WebpackIsomorphicTools = require('webpack-isomorphic-tools'); 24 | global.webpackIsomorphicTools = new WebpackIsomorphicTools(require('../webpack/webpack-isomorphic-tools')) 25 | .development(__DEVELOPMENT__) 26 | .server(rootDir, function() { 27 | require('../src/server'); 28 | }); 29 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | node: 3 | version: 4.0 4 | environment: 5 | CONTINUOUS_INTEGRATION: true 6 | 7 | dependencies: 8 | cache_directories: 9 | - node_modules 10 | override: 11 | - npm prune && npm install 12 | 13 | test: 14 | override: 15 | - npm run lint 16 | - npm test 17 | - npm run test-node 18 | -------------------------------------------------------------------------------- /docs/AddingAPage/AddingAPage.md: -------------------------------------------------------------------------------- 1 | # Adding A Hello Page 2 | 3 | This guide adds a `/hello` page to the sample application by 4 | following the existing outline. 5 | 6 | ## Using Ack on About 7 | 8 | Searching strings is one way to [grok](https://en.wikipedia.org/wiki/Grok) the structure 9 | of the kit and sample application. You can use *grep* or [ack](http://beyondgrep.com) (`brew install ack`). 10 | I use *ack* with this alias: 11 | 12 | ![ick Alias](ick_alias.png) 13 | 14 | Looking with `ick about` and ignoring documentation, the word *about* appears in these files: 15 | 16 | ![ick for About](ick_about.png) 17 | 18 | ## Add the Hello page container 19 | 20 | A new page requires new page renderer. Copy the About page to a 21 | new directory and trim out almost all of it: 22 | 23 | * `cd ./src/containers && mkdir ./Hello` because each container goes in its own 24 | directory by convention. 25 | * `cp About/About.js Hello/Hello.js` 26 | 27 | Edit `Hello/Hello.js` into this file: 28 | 29 | ![New Hello.js](new_hello.png) 30 | 31 | 32 | 33 | ## Edit three files to add Hello 34 | 35 | #### Add to `./src/containers/index.js` to include and export the React component: 36 | 37 | ![Edit index.js](edit_index.png) 38 | 39 | #### Add to `./routes.js` to connect the `/hello` url path to the component: 40 | 41 | ![Edit routes.js 1](edit_route1.png) 42 | ![Edit routes.js 2](edit_route2.png) 43 | 44 | #### Add to `./src/containers/App/App.js` to add "Hello" to the NavBar 45 | 46 | ![Edit App.js](edit_app.png) 47 | 48 | And voila, the new 'Hello' page: 49 | 50 | ![Show Hello](show_hello.png) 51 | 52 | # Take-away: Notice the trade-offs 53 | 54 | The task of adding a new page exemplifies two trade-offs in the kit: 55 | **code versus convention** and the **cut and paste** style. 56 | 57 | Convention is a set of constraining rules that automatically trigger 58 | routine configuration tasks. For example, WebPack automatically picked up the 59 | new directory `./src/containers/Hello` without adding to any configuration files. 60 | 61 | On the other hand, routine code was added to `./src/containers/index.js` and 62 | `./src/routes.js` to handle the new page. A convention could automatically 63 | accomplish the same tasks at either compile or run time. The cost is new 64 | constraints, such as requiring `Hello/Hello.js` to be renamed 65 | `HelloPage/HelloPage.js`. 66 | 67 | Following a style in the code that has no automatic effects is just organic 68 | growth, not convention. For example, developers reading `./src/containers/index.js` 69 | must stop and figure out why all subdirectories except `DevTools` are exported. 70 | (`DevTools`)[`./src/containers/DevTools/DevTools.js`](https://github.com/erikras/react-redux-universal-hot-example/blob/master/src/containers/DevTools/DevTools.js) 71 | contains a single function which should be 72 | [randomly](https://github.com/erikras/react-redux-universal-hot-example/issues/808) 73 | moved to `./src/utils` or `./src/helpers`. Using a convention rule that all 74 | containers must contain an exported React component would raise an error. 75 | Organic growth leads to disorder in a project. 76 | 77 | Similarly, the **cut and paste** style of coding also degrades the project. 78 | For example, In `App.js`, the new *NavItem* tag included a new value for the 79 | *eventkey* property. The *eventkey* property is 80 | [poorly](https://github.com/react-bootstrap/react-bootstrap/issues/320) 81 | [understood](https://github.com/react-bootstrap/react-bootstrap/issues/432). 82 | All *eventkey* fields in `App.js` are unused and can be removed. The 83 | **cut and paste** style just compounds an 84 | [old error](https://github.com/erikras/react-redux-universal-hot-example/commit/d67a79c1e7da5367dc8922019ca726e69d56bf0e) 85 | and reinforces confusion. 86 | 87 | ![Edit App revisted](edit_app2.png) 88 | 89 | The use of the **cut and paste** style raises well known issues in 90 | maintenance, documentation, and code quality. It is not for use in 91 | production code. 92 | 93 | Some choices about trade-offs are easier than others. 94 | -------------------------------------------------------------------------------- /docs/AddingAPage/edit_app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urtubia/react-redux-passport-sequelize-example/1ecbf79ebd956018399b138e72403b1d14ed4dc4/docs/AddingAPage/edit_app.png -------------------------------------------------------------------------------- /docs/AddingAPage/edit_app2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urtubia/react-redux-passport-sequelize-example/1ecbf79ebd956018399b138e72403b1d14ed4dc4/docs/AddingAPage/edit_app2.png -------------------------------------------------------------------------------- /docs/AddingAPage/edit_index.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urtubia/react-redux-passport-sequelize-example/1ecbf79ebd956018399b138e72403b1d14ed4dc4/docs/AddingAPage/edit_index.png -------------------------------------------------------------------------------- /docs/AddingAPage/edit_route1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urtubia/react-redux-passport-sequelize-example/1ecbf79ebd956018399b138e72403b1d14ed4dc4/docs/AddingAPage/edit_route1.png -------------------------------------------------------------------------------- /docs/AddingAPage/edit_route2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urtubia/react-redux-passport-sequelize-example/1ecbf79ebd956018399b138e72403b1d14ed4dc4/docs/AddingAPage/edit_route2.png -------------------------------------------------------------------------------- /docs/AddingAPage/ick_about.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urtubia/react-redux-passport-sequelize-example/1ecbf79ebd956018399b138e72403b1d14ed4dc4/docs/AddingAPage/ick_about.png -------------------------------------------------------------------------------- /docs/AddingAPage/ick_alias.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urtubia/react-redux-passport-sequelize-example/1ecbf79ebd956018399b138e72403b1d14ed4dc4/docs/AddingAPage/ick_alias.png -------------------------------------------------------------------------------- /docs/AddingAPage/new_hello.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urtubia/react-redux-passport-sequelize-example/1ecbf79ebd956018399b138e72403b1d14ed4dc4/docs/AddingAPage/new_hello.png -------------------------------------------------------------------------------- /docs/AddingAPage/show_hello.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urtubia/react-redux-passport-sequelize-example/1ecbf79ebd956018399b138e72403b1d14ed4dc4/docs/AddingAPage/show_hello.png -------------------------------------------------------------------------------- /docs/AddingToHomePage/AddingToHomePage.md: -------------------------------------------------------------------------------- 1 | # Adding Hello, World as static text 2 | 3 | Printing *Hello, World!* is a traditional task. This guides you through adding the text "Hello, World!" to the 4 | home page of the sample application. 5 | 6 | ## Find the home page 7 | 8 | First, find the correct file to change by walking through the kit's directory tree: 9 | 10 | ![Finding The Home Page 1](find_home1.png) 11 | 12 | 13 | ![Finding The Home Page 2](find_home2.png) 14 | 15 | ![Finding The Home Page 3](find_home3.png) 16 | 17 | ![Finding The Home Page 4](find_home4.png) 18 | 19 | So, the likely file is `src/containers/Home/Home.js`. 20 | 21 | ## Start the server and open the browser 22 | 23 | Execute `npm run dev` and open http://localhost:3000: 24 | 25 | * `./package.json`, using [concurrently](https://www.npmjs.com/package/concurrently) 26 | and [better-npm-run](https://www.npmjs.com/package/better-npm-run), runs 27 | `./webpack/webpack-dev-server.js` on port 3001; runs `./bin/server.js` for HTTP on port 3000; 28 | and runs `./bin/api.js` for the REST API on port 3030. 29 | 30 | * `./bin/server.js` calls `./src/server.js` and uses the [HMR plugin](http://andrewhfarmer.com/webpack-hmr-tutorial/) 31 | for hot reloading, meaning the browser refreshes automatically when any file in `./src` is changed. 32 | 33 | * `./webpack/webpack-dev-server` does teh actual compilation with the 34 | [webpack dev middleware package](https://github.com/webpack/webpack-dev-middleware) to provide a key feature found 35 | in Glup: compilation without writing intermediate files to disk. Configuring webpack 36 | [can be confusing](https://medium.com/@dtothefp/why-can-t-anyone-write-a-simple-webpack-tutorial-d0b075db35ed#.cle1vv5ql). 37 | 38 | * `./bin/api.js` calls `./api/api.js`. It receives incoming REST requests as JSON objects and responds with 39 | other JSON objects. 40 | 41 | ## Change the text 42 | 43 | Add the static text to (`src/containers/Home/Home.js`): 44 | 45 | ![Add Hello Header to Home](add_home.png) 46 | 47 | 48 | When you save the file to disk, the change to the `./src` directory is picked up by the 49 | [piping](https://www.npmjs.com/package/piping) module, triggering the webpack-dev-server to rebuild 50 | `./static/dist/[checksum].js`, and triggering a stub injected into the HTML file served to the browser to 51 | reload. The rebuilding processes through webpack middleware and plugins that compile `*.sccs` files, 52 | transpile JAX and ES6 (or ES7), and bundles together all the resources into one package in about 6 seconds. 53 | That is, the browser will show "Hello, World!" on your web page in about 6 seconds: 54 | 55 | ![Hello World rendered on home page](hello_rendered.png) 56 | 57 | ## Conclusion 58 | 59 | You added **Hello, World!**. The process is [as clear as is the summer's sun](https://www.youtube.com/watch?v=EhGiSfv5FJk&t=3m23s). 60 | 61 | -------------------------------------------------------------------------------- /docs/AddingToHomePage/add_home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urtubia/react-redux-passport-sequelize-example/1ecbf79ebd956018399b138e72403b1d14ed4dc4/docs/AddingToHomePage/add_home.png -------------------------------------------------------------------------------- /docs/AddingToHomePage/find_home1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urtubia/react-redux-passport-sequelize-example/1ecbf79ebd956018399b138e72403b1d14ed4dc4/docs/AddingToHomePage/find_home1.png -------------------------------------------------------------------------------- /docs/AddingToHomePage/find_home2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urtubia/react-redux-passport-sequelize-example/1ecbf79ebd956018399b138e72403b1d14ed4dc4/docs/AddingToHomePage/find_home2.png -------------------------------------------------------------------------------- /docs/AddingToHomePage/find_home3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urtubia/react-redux-passport-sequelize-example/1ecbf79ebd956018399b138e72403b1d14ed4dc4/docs/AddingToHomePage/find_home3.png -------------------------------------------------------------------------------- /docs/AddingToHomePage/find_home4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urtubia/react-redux-passport-sequelize-example/1ecbf79ebd956018399b138e72403b1d14ed4dc4/docs/AddingToHomePage/find_home4.png -------------------------------------------------------------------------------- /docs/AddingToHomePage/hello_rendered.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urtubia/react-redux-passport-sequelize-example/1ecbf79ebd956018399b138e72403b1d14ed4dc4/docs/AddingToHomePage/hello_rendered.png -------------------------------------------------------------------------------- /docs/ApiConfig.md: -------------------------------------------------------------------------------- 1 | # Switching to a real API 2 | 3 | Chances are, once you get comfortable with this setup, you'll want to hook into some existing API rather than use the simple one that comes with this project. Here's how: 4 | 5 | ## Update `package.json` 6 | 7 | First things first, you need to add `APIHOST` settings in `package.json`. If you look in `src/config.js`, you'll see that it's already configured to read this `APIHOST` setting if it's present. 8 | 9 | If the port you use differs between your dev & prod API hosts, you may want to get rid of the `APIPORT` setting, including it right in `APIHOST`. Same with the protocol – if you use HTTP in dev but HTTPS in prod, you may want to include the protocol right in `APIHOST`, and then get rid of the explicit `"http://"` found in the next section. 10 | 11 | ## Update `ApiClient` 12 | 13 | Open up `src/helpers/ApiClient.js`. You'll see this line: 14 | 15 | ``` javascript 16 | if (__SERVER__) { 17 | // Prepend host and port of the API server to the path. 18 | return 'http://' + config.apiHost + adjustedPath; 19 | } 20 | ``` 21 | 22 | If you added `http://` or `https://` to your APIHOST setting, then you need to remove it here. 23 | 24 | In this file, you'll also see that there's a `/api` that gets prepended to the URL when on the client side. That gets routed through a proxy that's configured in server.js, which we'll get to next. 25 | 26 | Why do you need a proxy? So that the `APIHOST` can be set as part of the Node environment, and your client side code can still work. A user's browser doesn't have access to your server's Node environment, so instead the client-side code makes all API calls to this `/api` proxy, which the server configures to hit your real API. That way you can control everything sanely, through environment variables, and set different API endpoints for your different environments. 27 | 28 | ## Update `server.js` 29 | 30 | To update the proxy, find this chunk in `src/server.js`: 31 | 32 | ``` javascript 33 | const proxy = httpProxy.createProxyServer({ 34 | target: 'http://' + config.apiHost, 35 | ws: true 36 | }); 37 | ``` 38 | 39 | You'll want to change this in a few ways: 40 | 41 | ### 1. Update `target` protocol 42 | 43 | If you changed APIHOST to include the `http://` or `https://` protocol, then get rid of the `'http://' +` in the `target` setting. Note that you'll need to restart your server after making these changes or things will break. 44 | 45 | ### 2. Decide if you need WebSockets 46 | 47 | The `ws: true` setting is there to support WebSockets connections, which this demo app supports using [socket.io](http://socket.io/). If your API doesn't use WebSockets, then you can remove this line. 48 | 49 | ### 3. Add a `changeOrigin` setting 50 | 51 | This might be the most important part! It's possible that your API lives at a totally different URL than your front-end app. If that's the case, then you need to add a `changeOrigin` setting. 52 | 53 | Here's an example of what the final chunk of code might look like: 54 | 55 | ``` javascript 56 | const proxy = httpProxy.createProxyServer({ 57 | target: config.apiHost, 58 | changeOrigin: true 59 | }); 60 | ``` 61 | 62 | Finally, after doing all of that, you can get rid of the demo API. 63 | 64 | ## Get rid of stuff 65 | 66 | You can remove the whole `api` folder, as well as `bin/api.js`. 67 | 68 | Once you do that, you'll also need to remove the lines in `package.json` that called those things. Remove all this: 69 | 70 | * ` \"npm run start-prod-api\"` from the `start` script command 71 | * ` \"npm run start-dev-api\"` from the `dev` script command 72 | * the `start-prod-api` and `start-dev-api` scripts altogether 73 | * the ` api` argument from the `lint` script 74 | * the `test-node` and `test-node-watch` scripts, which were there to test the demo API 75 | * the `start-prod-api` and `start-dev-api` settings in the `betterScripts` section 76 | 77 | If you want, you can also remove all references to `socket`, if you're not using it. 78 | -------------------------------------------------------------------------------- /docs/Ducks.md: -------------------------------------------------------------------------------- 1 | This document has found [another, hopefully permanent, home](https://github.com/erikras/ducks-modular-redux). 2 | 3 | Quack. 4 | -------------------------------------------------------------------------------- /docs/ExploringTheDemoApp/ExploringTheDemoApp.md: -------------------------------------------------------------------------------- 1 | # Guide - Exploring the Demo App 2 | 3 | This guide covers your first look and can be used even before installing software. 4 | 5 | ## Overview 6 | 7 | This project is a kit for developing interactive applications in JavaScript centered 8 | around React and Redux. Like all JavaScript kits, it includes a large number of configured 9 | modules and a sample, or Demo App, from which to start your application. This guide walks 10 | through that Demo App to show some features and code. 11 | 12 | ### Open the demo in your browser 13 | 14 | The project hosts a running demo on Heroku, a hosting company. Open 15 | [https://react-redux.herokuapp.com/](https://react-redux.herokuapp.com/) in your browser to see this page: 16 | 17 | ![Screenshot](frontpage.png) 18 | 19 | Much of the text is cut-and-paste from the project's 20 | [README.md](https://github.com/erikras/react-redux-universal-hot-example/blob/master/README.md) file into 21 | the code for this page [./src/containers/Home/Home.js](https://github.com/erikras/react-redux-universal-hot-example/blob/master/src/containers/Home/Home.js). 22 | 23 | The text provides a one line overview of about twenty of the main 24 | modules of hundreds shown during installation. The selection 25 | and configuration of all these modules is the value of using a kit. When you run across 26 | a module you have never heard of and want to get a quick overview, the fastest way is 27 | to google for 'slideshare theModuleName' and skim someone's presentation. 28 | 29 | The page is rendered from HTML including React components coded as custom HTML tags. 30 | The components use properties to alter appearance and sets of data. Notice some of the components on the page: 31 | 32 | ![Screenshot with Annotations](frontpage_markup.png) 33 | 34 | ### Explore the Widgets Page 35 | 36 | Click on *Widgets* link on the top of the screen. You come to a page with some arbitrary widgets and more logic 37 | in the form. Notice how much state affects the display and formatting of buttons: 38 | 39 | ![Screenshot with Annotations](widgets_markup.png) 40 | 41 | ### Explore the Survey Page 42 | 43 | Click on the *Survey* link. Following the programming style of this kit, the code for this page is 44 | spread over a [Survey container][scont], a [SurveyForm component][scomp], mentioned in the 45 | [container][conlist] and [component][complist] lists, 46 | mentioned in the [routes][routes] function and the navigation of the main [App][app]. The code also uses 47 | various libraries for React, Redux, validation, memoize and other functions. Learn to use [ack](http://beyondgrep.com) 48 | or the project wide search built into your editor. 49 | 50 | Try clicking on the 'Initialize Form' button and then hitting Submit. You will see just an error under 51 | 'Little Bobby Tables'. Now click in the email field then the name field. You now see errors in both 52 | the name and the email. Even with a good kit, forms can be difficult to code. 53 | 54 | ![Screenshot with Annotations](survey_markup.png) 55 | [scont]: https://github.com/erikras/react-redux-universal-hot-example/tree/master/src/containers/Survey 56 | [scomp]: https://github.com/erikras/react-redux-universal-hot-example/tree/master/src/components/SurveyForm 57 | [conlist]: https://github.com/erikras/react-redux-universal-hot-example/blob/master/src/containers/index.js 58 | [complist]: https://github.com/erikras/react-redux-universal-hot-example/blob/master/src/components/index.js 59 | [routes]: https://github.com/erikras/react-redux-universal-hot-example/blob/master/src/routes.js 60 | [app]: https://github.com/erikras/react-redux-universal-hot-example/tree/master/src/containers/App/App.js 61 | 62 | ### Explore the About Page 63 | 64 | Click on the *About* link. The source for this page 65 | [./src/containers/About/About.js](https://github.com/erikras/react-redux-universal-hot-example/blob/master/src/containers/About/About.js) 66 | uses a casual mix of HTML, ECMA7 JavaScript, and React components. This translates into 67 | simple JavaScript code for the browser. Notice how the local state `showKitten` being false causes no 68 | `div` or `img` tag in the output. 69 | 70 | ![Screenshot with Annotations](about_markup.png) 71 | 72 | ### Explore the Login Page 73 | 74 | Finally, click on the *Login* page and explore. Looking at the styling for this page 75 | [./src/containers/Login/Login.scss]](https://github.com/erikras/react-redux-universal-hot-example/blob/master/src/containers/Login/Login.scss) 76 | will show an example of how the using styling files litters the code base with extra files. 77 | Consider the alternative of using 78 | [Inline Styles](https://github.com/erikras/react-redux-universal-hot-example/blob/master/docs/InlineStyles.md). 79 | 80 | # The Take Away 81 | 82 | Looking through each page of the DemoApp will lead you to more questions which will keep you 83 | searching and learning and you will slowly master this technology. 84 | 85 | Here are some additional quests you could undertake: 86 | 87 | * How do the About page MiniBar and the status bar share data about the time last loaded? 88 | * How would you add a fourth counter that incremented by two? How many files would you need 89 | to touch? 90 | * What order are calls made when you click "Reload Widgets" on the widgets page? 91 | * Why does surveyValidation use memoize? 92 | 93 | Install, hack, explore! 94 | 95 | *All guides are works in progress, and pull requests are always welcome. If you make an 96 | accepted pull request and live in Silicon Valley, I'll treat you to coffee. -- Charles* 97 | 98 | 99 | -------------------------------------------------------------------------------- /docs/ExploringTheDemoApp/about_markup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urtubia/react-redux-passport-sequelize-example/1ecbf79ebd956018399b138e72403b1d14ed4dc4/docs/ExploringTheDemoApp/about_markup.png -------------------------------------------------------------------------------- /docs/ExploringTheDemoApp/frontpage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urtubia/react-redux-passport-sequelize-example/1ecbf79ebd956018399b138e72403b1d14ed4dc4/docs/ExploringTheDemoApp/frontpage.png -------------------------------------------------------------------------------- /docs/ExploringTheDemoApp/frontpage_markup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urtubia/react-redux-passport-sequelize-example/1ecbf79ebd956018399b138e72403b1d14ed4dc4/docs/ExploringTheDemoApp/frontpage_markup.png -------------------------------------------------------------------------------- /docs/ExploringTheDemoApp/survey_markup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urtubia/react-redux-passport-sequelize-example/1ecbf79ebd956018399b138e72403b1d14ed4dc4/docs/ExploringTheDemoApp/survey_markup.png -------------------------------------------------------------------------------- /docs/ExploringTheDemoApp/widgets_markup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urtubia/react-redux-passport-sequelize-example/1ecbf79ebd956018399b138e72403b1d14ed4dc4/docs/ExploringTheDemoApp/widgets_markup.png -------------------------------------------------------------------------------- /docs/InlineStyles.md: -------------------------------------------------------------------------------- 1 | # Inline Styles 2 | 3 | In the long term, CSS, LESS and SASS are dead. To keep this project on the bleeding edge, we should drop SASS support in favor of inline styles. 4 | 5 | ## Why? 6 | 7 | I think the case is made pretty strongly in these three presentations. 8 | 9 | Christopher Chedeau | Michael Chan | Colin Megill 10 | --- | --- | --- 11 | [![CSS In Your JS by Christopher Chedeau](https://i.vimeocdn.com/video/502495328_295x166.jpg)](http://blog.vjeux.com/2014/javascript/react-css-in-js-nationjs.html) | [![Michael Chan - Inline Styles: themes, media queries, contexts, & when it's best to use CSS](https://i.ytimg.com/vi/ERB1TJBn32c/mqdefault.jpg)](https://www.youtube.com/watch?v=ERB1TJBn32c) | [![Colin Megill - Inline Styles are About to Kill CSS](https://i.ytimg.com/vi/NoaxsCi13yQ/mqdefault.jpg)](https://www.youtube.com/watch?v=NoaxsCi13yQ) 12 | 13 | Clearly this is the direction in which web development is moving. 14 | 15 | ## Why not? 16 | 17 | At the moment, all the inline CSS libraries suffer from some or all of these problems: 18 | 19 | * Client side only 20 | * No vendor auto prefixing (requires `User-Agent` checking on server side) 21 | * No server side media queries, resulting in a flicker on load to adjust to client device width 22 | 23 | Ideally, a library would allow for all the benefits of inline calculable styles, but, in production, would allow some generation of a CSS block, with media queries to handle device width conditionals, to be inserted into the page with a `