|
1 | 1 | # Installation |
2 | | -Since the repository is private, you will get a **GitHub Personal Access Token ** and an account that can access the packages. Substitute that value in the commands below. If you dont' have this, ask [[email protected]](mailto:[email protected]) to give you one. |
3 | 2 |
|
4 | | -Check the [CHANGELOG](https://github.com/shakacode/react_on_rails_pro/blob/master/CHANGELOG.md) to see what version you want. |
| 3 | +React on Rails Pro packages are published publicly on npmjs.org and RubyGems.org. Installation requires a valid **license token** for runtime validation. Contact [[email protected]](mailto:justin@shakacode.com) to purchase a license. |
5 | 4 |
|
6 | | -# Version |
| 5 | +Check the [CHANGELOG](https://github.com/shakacode/react_on_rails/blob/master/CHANGELOG.md) to see what version you want. |
7 | 6 |
|
8 | | -For the below docs, find the desired `<version>` in the CHANGELOG. Note, for pre-release versions, gems have all periods, and node packages uses a dash, like gem `3.0.0.rc.0` and node package `3.0.0-rc.0`. |
| 7 | +## Version Format |
9 | 8 |
|
10 | | -# Ruby |
11 | | -## Gem Installation |
12 | | -1. Ensure your **Rails** app is using the **react_on_rails** gem, version greater than 11.0.7. |
13 | | -1. Add the `react_on_rails_pro` gem to your **Gemfile**. Substitute the appropriate version number. |
14 | | - |
15 | | -## Gemfile Change |
| 9 | +For the below docs, find the desired `<version>` in the CHANGELOG. Note that for pre-release versions: |
| 10 | +- Gems use all periods: `16.2.0.beta.1` |
| 11 | +- NPM packages use dashes: `16.2.0-beta.1` |
16 | 12 |
|
17 | | -Replace the following in the snippet for the Gemfile |
18 | | -1. `<account>` for the api key |
19 | | -2. `<api-key>` |
20 | | -3. `<version>` desired |
| 13 | +# Ruby Gem Installation |
21 | 14 |
|
22 | | -```ruby |
23 | | -source "https://<rorp-account>:<token>@"\ |
24 | | - "rubygems.pkg.github.com/shakacode-tools" do |
25 | | - gem "react_on_rails_pro", "<version>" |
26 | | -end |
27 | | -``` |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +Ensure your **Rails** app is using the **react_on_rails** gem, version 16.0.0 or higher. |
28 | 18 |
|
29 | | -## Alternate installation keeping the key out of your Gemfile |
| 19 | +## Install react_on_rails_pro Gem |
| 20 | + |
| 21 | +Add the `react_on_rails_pro` gem to your **Gemfile**: |
30 | 22 |
|
31 | 23 | ```ruby |
32 | | -source "https://rubygems.pkg.github.com/shakacode-tools" do |
33 | | - gem "react_on_rails_pro", "<version>" |
34 | | -end |
| 24 | +gem "react_on_rails_pro", "~> 16.1" |
35 | 25 | ``` |
36 | | -Or use the `gem install` command: |
| 26 | + |
| 27 | +Then run: |
37 | 28 |
|
38 | 29 | ```bash |
39 | | -gem install react_on_rails_pro --version "<version>> --source "https://rubygems.pkg.github.com/shakacode-tools" |
| 30 | +bundle install |
40 | 31 | ``` |
41 | 32 |
|
42 | | -Then edit your permissions for bundler at the command line: |
| 33 | +Or install directly: |
43 | 34 |
|
| 35 | +```bash |
| 36 | +gem install react_on_rails_pro --version "<version>" |
44 | 37 | ``` |
45 | | -bundle config set rubygems.pkg.github.com <username>:<token> |
| 38 | + |
| 39 | +## License Configuration |
| 40 | + |
| 41 | +Set your license token as an environment variable: |
| 42 | + |
| 43 | +```bash |
| 44 | +export REACT_ON_RAILS_PRO_LICENSE="your-license-token-here" |
46 | 45 | ``` |
47 | 46 |
|
48 | | -## Using a branch in your Gemfile |
49 | | -Note, you should probably use an ENV value for the token so that you don't check this into your source code. |
50 | | - ```ruby |
51 | | - gem "react_on_rails_pro", version: "<version>", git: "https://[your-github-token]:[email protected]/shakacode/react_on_rails_pro.git", tag: "<version>" |
52 | | - ``` |
| 47 | +Or configure it in your Rails initializer (not recommended for production): |
| 48 | + |
| 49 | +```ruby |
| 50 | +# config/initializers/react_on_rails_pro.rb |
| 51 | +ReactOnRailsPro.configure do |config| |
| 52 | + config.license_token = ENV["REACT_ON_RAILS_PRO_LICENSE"] |
| 53 | +end |
| 54 | +``` |
53 | 55 |
|
54 | 56 | ## Rails Configuration |
55 | | -You don't need to create an initializer if you are satisfied with the default as described in |
56 | | -[Configuration](./configuration.md) |
57 | 57 |
|
58 | | -# Node Package |
59 | | -Note, you only need to install the Node Package if you are using the standalone node renderer, `NodeRenderer`. |
| 58 | +You don't need to create an initializer if you are satisfied with the defaults as described in [Configuration](./configuration.md). |
60 | 59 |
|
61 | | -## Installation |
| 60 | +For basic setup: |
62 | 61 |
|
63 | | -1. Create a subdirectory of your rails project for the Node renderer. Let's use `react-on-rails-pro`. |
64 | | - |
65 | | -2. Create a file `react-on-rails-pro/.npmrc` with the following |
| 62 | +```ruby |
| 63 | +# config/initializers/react_on_rails_pro.rb |
| 64 | +ReactOnRailsPro.configure do |config| |
| 65 | + # Your configuration here |
| 66 | + # See docs/configuration.md for all options |
| 67 | +end |
66 | 68 | ``` |
67 | | -always-auth=true |
68 | | -//npm.pkg.github.com/:_authToken=<token> |
69 | | -@shakacode-tools:registry=https://npm.pkg.github.com |
| 69 | + |
| 70 | +# Node Package Installation |
| 71 | + |
| 72 | +**Note:** You only need to install the Node Package if you are using the standalone node renderer (`NodeRenderer`). If you're using `ExecJS` (the default), skip this section. |
| 73 | + |
| 74 | +## Install react-on-rails-pro-node-renderer |
| 75 | + |
| 76 | +### Using npm: |
| 77 | + |
| 78 | +```bash |
| 79 | +npm install react-on-rails-pro-node-renderer |
| 80 | +``` |
| 81 | + |
| 82 | +### Using yarn: |
| 83 | + |
| 84 | +```bash |
| 85 | +yarn add react-on-rails-pro-node-renderer |
70 | 86 | ``` |
71 | 87 |
|
72 | | -3. Create a `react-on-rails-pro/package.json` |
| 88 | +### Add to package.json: |
| 89 | + |
73 | 90 | ```json |
74 | 91 | { |
75 | | - "private": true, |
76 | 92 | "dependencies": { |
77 | | - "@shakacode-tools/react-on-rails-pro-node-renderer": "<version>" |
78 | | - }, |
79 | | - "scripts": { |
80 | | - "node-renderer": "echo 'Starting React on Rails Pro Node Renderer.' && node ./react-on-rails-pro-node-renderer.js" |
| 93 | + "react-on-rails-pro-node-renderer": "16.1.1" |
81 | 94 | } |
82 | 95 | } |
83 | 96 | ``` |
84 | 97 |
|
85 | | -4. Be sure to run `npm i` **and not** `yarn` as only npm seems to work with the private github packages. |
| 98 | +## Node Renderer Setup |
86 | 99 |
|
87 | | -If you really want to use yarn, see [Yarn can't find private Github npm registry](https://stackoverflow.com/questions/58316109/yarn-cant-find-private-github-npm-registry) |
88 | | -
|
89 | | -5. You can start the renderer with either the executable `node-renderer` or, preferably, with |
90 | | - a startup JS file, say called `react-on-rails-pro/react-on-rails-pro-node-renderer.js` with |
91 | | - these contents. _Note the use of the namespaced **`@shakacode-tools/react-on-rails-pro-node-renderer`** for the package. |
| 100 | +Create a JavaScript file to configure and launch the node renderer, for example `react-on-rails-pro-node-renderer.js`: |
92 | 101 |
|
93 | 102 | ```js |
94 | | -const path = require('path') |
95 | | -const { |
96 | | - reactOnRailsProNodeRenderer, |
97 | | -} = require('@shakacode-tools/react-on-rails-pro-node-renderer') |
| 103 | +const path = require('path'); |
| 104 | +const { reactOnRailsProNodeRenderer } = require('react-on-rails-pro-node-renderer'); |
98 | 105 |
|
99 | | -const env = process.env |
| 106 | +const env = process.env; |
100 | 107 |
|
101 | 108 | const config = { |
102 | 109 | bundlePath: path.resolve(__dirname, '../.node-renderer-bundles'), |
103 | 110 |
|
104 | 111 | // Listen at RENDERER_PORT env value or default port 3800 |
105 | 112 | logLevel: env.RENDERER_LOG_LEVEL || 'debug', // show all logs |
106 | 113 |
|
107 | | - // See value in /config/initializers/react_on_rails_pro.rb. Should use env |
108 | | - // value in real app. |
109 | | - password: 'myPassword1', |
| 114 | + // Password for Rails <-> Node renderer communication |
| 115 | + // See value in /config/initializers/react_on_rails_pro.rb |
| 116 | + password: env.RENDERER_PASSWORD || 'changeme', |
110 | 117 |
|
111 | | - // Save bundle to "tmp/bundles" dir of our dummy app |
112 | | - // This is the default |
113 | 118 | port: env.RENDERER_PORT || 3800, |
114 | 119 |
|
115 | 120 | // supportModules should be set to true to allow the server-bundle code to |
116 | | - // see require, exports, etc. |
117 | | - // `false` is like the ExecJS behavior |
118 | | - // this option is required to equal `true` in order to use loadable components |
| 121 | + // see require, exports, etc. (`false` is like the ExecJS behavior) |
| 122 | + // This option is required to equal `true` in order to use loadable components |
119 | 123 | supportModules: true, |
120 | 124 |
|
121 | 125 | // workersCount defaults to the number of CPUs minus 1 |
122 | | - workersCount: Number(process.env.NODE_RENDERER_CONCURRENCY || 3), |
123 | | -
|
124 | | - // Next 2 params, allWorkersRestartInterval and |
125 | | - // delayBetweenIndividualWorkerRestarts must both should be set if you wish |
126 | | - // to have automatic worker restarting, say to clear memory leaks. |
127 | | - // time is in minutes between restarting all workers |
128 | | - // Enable next 2 if the renderer is running out of memory |
129 | | - // allWorkersRestartInterval: 15, |
130 | | - // time in minutes between each worker restarting when restarting all workers |
131 | | - // delayBetweenIndividualWorkerRestarts: 2, |
132 | | -} |
| 126 | + workersCount: Number(env.NODE_RENDERER_CONCURRENCY || 3), |
| 127 | + |
| 128 | + // Optional: Automatic worker restarting (for memory leak mitigation) |
| 129 | + // allWorkersRestartInterval: 15, // minutes between restarting all workers |
| 130 | + // delayBetweenIndividualWorkerRestarts: 2, // minutes between each worker restart |
| 131 | +}; |
133 | 132 |
|
134 | 133 | // Renderer detects a total number of CPUs on virtual hostings like Heroku |
135 | 134 | // or CircleCI instead of CPUs number allocated for current container. This |
136 | 135 | // results in spawning many workers while only 1-2 of them really needed. |
137 | 136 | if (env.CI) { |
138 | | - config.workersCount = 2 |
| 137 | + config.workersCount = 2; |
139 | 138 | } |
140 | 139 |
|
141 | | -reactOnRailsProNodeRenderer(config) |
| 140 | +reactOnRailsProNodeRenderer(config); |
142 | 141 | ``` |
143 | 142 |
|
144 | | -## Instructions for using a branch |
| 143 | +Add a script to your `package.json`: |
145 | 144 |
|
146 | | -Install the node-renderer executable, possibly globally. Substitute the branch name or tag for `master` |
| 145 | +```json |
| 146 | +{ |
| 147 | + "scripts": { |
| 148 | + "node-renderer": "node ./react-on-rails-pro-node-renderer.js" |
| 149 | + } |
| 150 | +} |
147 | 151 | ``` |
148 | | -yarn global add https://<your-github-token>:[email protected]/shakacode/react_on_rails_pro.git\#master |
| 152 | + |
| 153 | +Start the renderer: |
| 154 | + |
| 155 | +```bash |
| 156 | +npm run node-renderer |
149 | 157 | ``` |
150 | 158 |
|
151 | | -This installs a binary `node-renderer`. |
| 159 | +## Rails Configuration for Node Renderer |
152 | 160 |
|
153 | | -### Using Github packages |
| 161 | +Configure Rails to use the remote node renderer: |
154 | 162 |
|
155 | | -Login into npm |
| 163 | +```ruby |
| 164 | +# config/initializers/react_on_rails_pro.rb |
| 165 | +ReactOnRailsPro.configure do |config| |
| 166 | + config.server_renderer = "NodeRenderer" |
156 | 167 |
|
157 | | -```bash |
158 | | -npm install @shakacode-tools/react-on-rails-pro-node-renderer@<version> |
159 | | -``` |
| 168 | + # Configure renderer connection |
| 169 | + config.renderer_url = ENV["REACT_RENDERER_URL"] || "http://localhost:3800" |
| 170 | + config.renderer_password = ENV["RENDERER_PASSWORD"] || "changeme" |
160 | 171 |
|
161 | | -or edit package.json directly |
162 | | -```json |
163 | | -"@shakacode-tools/react-on-rails-pro-node-renderer": "<version>" |
164 | | -``` |
| 172 | + # Enable prerender caching (recommended) |
| 173 | + config.prerender_caching = true |
| 174 | +end |
| 175 | +``` |
165 | 176 |
|
166 | | -### Configuration |
167 | | -See [NodeRenderer JavaScript Configuration](./node-renderer/js-configuration.md). |
| 177 | +### Configuration Options |
168 | 178 |
|
169 | | -#### Webpack Configuration |
170 | | -Set your server bundle webpack configuration to use a target of `node` per the [Webpack docs](https://webpack.js.org/concepts/targets/#usage). |
| 179 | +See [Rails Configuration Options](./configuration.md) for all available settings. |
171 | 180 |
|
172 | | -## Authentication when using Github packages |
173 | | -[Auth for the npm package](https://docs.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-npm-for-use-with-github-packages#authenticating-to-github-packages) |
| 181 | +Pay attention to: |
| 182 | +- `config.server_renderer = "NodeRenderer"` - Required to use node renderer |
| 183 | +- `config.renderer_url` - URL where your node renderer is running |
| 184 | +- `config.renderer_password` - Shared secret for authentication |
| 185 | +- `config.prerender_caching` - Enable caching (recommended) |
174 | 186 |
|
175 | | -Create a new ~/.npmrc file if one doesn't exist. |
176 | | -``` |
177 | | -//npm.pkg.github.com/:_authToken=TOKEN |
178 | | -``` |
| 187 | +## Webpack Configuration |
179 | 188 |
|
180 | | -To configure bundler if you don't want the token in your Gemfile: |
181 | | -``` |
182 | | -bundle config https://rubygems.pkg.github.com/OWNER USERNAME:TOKEN |
183 | | -``` |
| 189 | +Set your server bundle webpack configuration to use a target of `node` per the [Webpack docs](https://webpack.js.org/concepts/targets/#usage). |
| 190 | + |
| 191 | +## Additional Documentation |
| 192 | + |
| 193 | +- [Node Renderer Basics](./node-renderer/basics.md) |
| 194 | +- [Node Renderer JavaScript Configuration](./node-renderer/js-configuration.md) |
| 195 | +- [Rails Configuration Options](./configuration.md) |
| 196 | +- [Error Reporting and Tracing](./node-renderer/error-reporting-and-tracing.md) |
0 commit comments