diff --git a/samples/universal-react-node/README.md b/samples/universal-react-node/README.md index c1f755d85..74e7851d3 100644 --- a/samples/universal-react-node/README.md +++ b/samples/universal-react-node/README.md @@ -1,61 +1,55 @@ -# Electrode App with Electrode Modules -A sample Electrode app generated using `yo electrode` that demonstrates the usage of several Electrode modules. +# Electrode Boilerplate Universal React Node +- This repo is a sample Electrode app with the following Electrode modules: + - [Electrode Confippet](https://github.com/electrode-io/electrode-confippet) + - [Electrode CSRF JWT](https://github.com/electrode-io/electrode-csrf-jwt) + - [Electrode Javascript Bundle Viewer](https://github.com/electrode-io/electrify) + - [Electrode Redux Router Engine](https://github.com/electrode-io/electrode-redux-router-engine) -## Install and Run - -If cloning or forking this repo, simply install via `npm` and run with `gulp`: - -```bash -$ npm install -$ NODE_ENV=development gulp hot -``` - -The app should be accessible at http://127.0.0.1:3000/ - -## Starting from Scratch - -This app was generated using [yeoman](yeoman.io) and instructions for recreating it from scratch are provided below. - -First, install `yeoman` and `electrode-generator`: +## Install ```bash -$ npm install -g yo -$ npm install -g generator-electrode +git clone https://github.com/electrode-io/electrode-boilerplate-universal-react-node.git +cd hapiApp +npm install ``` -Scaffold a new app using `yeoman`: +## Run +- Start the electrode app in `development` environment: ```bash -$ mkdir electrode-app-csrf-jwt -$ cd electrode-app-csrf-jwt -$ yo electrode +$ NODE_ENV=development gulp hot ``` -At this point, you should be able to run the server locally: +- Start the electrode app in `production` environment: ```bash -$ npm install -$ NODE_ENV=development gulp hot +$ NODE_ENV=production gulp hot ``` -## Electrode Module Demos - -This application already contains demonstration code for the following modules. If you're starting from scratch using scaffolding, you can find instructions for adding and configuring individual modules below. - -- [Electrode Confippet](#electrode-confippet) -- [Electrode CSRF-JWT](#electrode-csrf-jwt) - -## Electrode Confippet +- Running in the selected environment should load the appropriate configuration settings -[Confippet](https://github.com/electrode-io/electrode-confippet) is a versatile utility for managing your NodeJS application configuration. Its goal is customization and extensibility, but offers a preset config out of the box. +## Instructions +- You can build the app from scratch by following the instructions below: + - [Electrode Confippet](#electrode-confippet) + - [Electrode CSRF JWT](#csrf-jwt) + - [Electrode Javascript Bundle Viewer](#bundle-viewer) + - [Electrode Redux Router Engine](#redux-router-engine) + +--- +## Electrode Confippet ## +- [Confippet](https://github.com/electrode-io/electrode-confippet) is a versatile utility for managing your NodeJS application configuration. Its goal is customization and extensibility, but offers a preset config out of the box. +- Scaffold an electrode app using the following commands: -### Installation +### Install ```bash -$ npm install electrode-confippet --save +npm install -g yo +npm install -g generator-electrode +yo electrode ``` -#### Config Files +#### Config +- Once the scaffolding is complete, open the following config files: ``` config @@ -64,9 +58,8 @@ config |_ production.json ``` -#### Development Environment - -Update the `config/development.json` to have the following settings: +#### Development environment +- Update the `config/development.json` to have the following settings: ```json { @@ -87,11 +80,10 @@ Update the `config/development.json` to have the following settings: } ``` -The above settings should show server log errors that may be beneficial for debugging, disable content encoding, and run the server in port 3000 +- The above settings should show server log errors that may be beneficial for debugging, disable content encoding, and run the server in port 3000 -#### Production Environment - -Update the `config/production.json` to have the following settings: +#### Production environment +- Update the `config/production.json` to have the following settings: ```json { @@ -117,9 +109,8 @@ Update the `config/production.json` to have the following settings: - The `connections` key are electrode server specific: https://github.com/electrode-io/electrode-server/tree/master/lib/config - Keys that exist in the `config/default.json` that are also in the other environment configs will be replaced by the environment specific versions -#### Confippet Require - -In Electrode, the configurations are loaded from `server/index.js` at this line: +#### Require +- In Electrode, the configurations are loaded from `server/index.js` at this line: ```javascript const config = require("electrode-confippet").config; @@ -128,8 +119,7 @@ const staticPathsDecor = require("electrode-static-paths"); require("electrode-server")(config, [staticPathsDecor()]); ``` -#### Running Electrode app - +#### Run - Start the electrode app in `development` environment: ```bash @@ -145,28 +135,25 @@ $ NODE_ENV=production gulp hot - Running in the selected environment should load the appropriate configuration settings --- - -## Electrode CSRF-JWT - +## Electrode CSRF-JWT [CSRF-JWT](https://github.com/electrode-io/electrode-csrf-jwt) is an Electrode plugin that allows you to authenticate HTTP requests using JWT in your Electrode applications. -### Installation - -Add the `electrode-csrf-jwt` component: +### Install +- Add the `electrode-csrf-jwt` component: ```bash -$ npm install electrode-csrf-jwt --save +npm install electrode-csrf-jwt --save ``` -Next, register the plugin with the Electrode server. Add the following configuration to the `plugins` section of `config/default.json`: +- Next, register the plugin with the Electrode server. Add the following configuration to the `plugins` section of `config/default.json`: ```json - "electrode-csrf-jwt": { - "options": { - "secret": "test", - "expiresIn": 60 - } - } +"electrode-csrf-jwt": { + "options": { + "secret": "test", + "expiresIn": 60 + } +} ``` That's it! CSRF protection will be automatically enabled for endpoints added to the app. CSRF JWT tokens will be returned in the headers and set as cookies for every response and must be provided as both a header and a cookie in every `POST` request. @@ -181,7 +168,7 @@ In addition to the above steps, the following modifications were made in order t * AJAX testing logic was added to `client/components/csrf.jsx` --- -## Electrode Javascript Bundle Viewer - How to use/integrate guide ## +## Electrode Javascript Bundle Viewer - How to use/integrate guide ## Electrode Javascript bundle viewer is named [electrify](https://github.com/electrode-io/electrify), it is a tool that helps for analyzing the module tree of webpack based projects. It's especially handy for catching large and/or duplicate modules which might be either bloating up your bundle or slowing down the build/install process. @@ -196,3 +183,12 @@ Electrode Javascript bundle viewer is named [electrify](https://github.com/elect When you install electrify globally using `sudo npm install -g electrode-electrify`, `electrify` command-line tool is made available as the quickest means of checking out your bundle. As of `electrode-electrify v1.0.0`, the tool takes any [webpack-stats](http://webpack.github.io/docs/node.js-api.html#stats-tojson) object as input and starts out a standalone HTML page as output in your browser, all you have to do is type `electrify --open` on your terminal. Head over to the electrify [repository](https://github.com/electrode-io/electrify#electrify) for a detailed view of the bundle viewer and checkout the source-code. [electrify](https://github.com/electrode-io/electrify) relies on webpack to generate the application modules/dependency tree and is independent of whichever server framework(hapijs, expressjs, etc.) you choose to use. + +--- +## Electrode Redux Router Engine ## +- [Redux Router Engine](https://github.com/electrode-io/electrode-redux-router-engine) handles async data for React Server Side Rendering using [react-router], Redux, and the [Redux Server Rendering] pattern. + +### Install +``` +npm install --save electrode-redux-router-engine +``` diff --git a/samples/universal-react-node/package.json b/samples/universal-react-node/package.json index 4a0def4a4..27f887451 100644 --- a/samples/universal-react-node/package.json +++ b/samples/universal-react-node/package.json @@ -25,6 +25,7 @@ "dependencies": { "bluebird": "^2.10.2", "electrode-csrf-jwt": "^3.0.1", + "electrode-redux-router-engine": "^1.0.0", "electrode-router-resolver-engine": "^1.0.0", "electrode-server": "^1.0.0", "electrode-static-paths": "^1.0.0",