- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 639
Node React Render JavaScript Configuration
        Justin Gordon edited this page Sep 10, 2018 
        ·
        1 revision
      
    You can configure the renderer with only ENV values using the provided bin file vm-renderer.
You can also create a custom configuration file to setup and launch the vm-renderer.
The values in this file must be kept in sync with with the config/initializers/react_on_rails_pro.rb file, as documented in [[Ruby Configuration].
Here are the options available for the JavaScript renderer configuration object, as well as the available default ENV values if using the command line program vm-renderer.
- 
port (default: process.env.RENDERER_PORT || 3800) - The port renderer should listen to. If setting the port, you might want to ensure the port usesprocess.env.PORTso it will use port number provided by Heroku environment.
- 
logLevel (default: process.env.RENDERER_LOG_LEVEL || 'info') - Log lever for renderer. Set it to'error'to turn logging off. Available levels are:{ error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5 }
- 
bundlePath (default: process.env.RENDERER_BUNDLE_PATH || '/tmp/react-on-rails-pro-vm-renderer-bundles') - path to temp directory where uploaded bundle files will be stored. For example you can set it topath.resolve(__dirname, './tmp/bundles')if you configured renderer from the/directory of your app.
- 
workersCount (default: env.RENDERER_WORKERS_COUNT || defaultWorkersCount()where default is your CPUs count - 1) - Number of workers that will be forked to serve rendering requests. If you set this manually make sure that value is a Number and is>= 1.
- 
password (default: env.RENDERER_PASSWORD) - Password expected to receive form Rails client to authenticate rendering requests. If no password set, no authentication will be required.
- 
allWorkersRestartInterval (default: env.RENDERER_ALL_WORKERS_RESTART_INTERVAL) - Interval in minutes between scheduled restarts of all cluster of workers. By default restarts are not enabled. If restarts are enabled,delayBetweenIndividualWorkerRestartsshould also be set.
- 
delayBetweenIndividualWorkerRestarts (default: env.RENDERER_DELAY_BETWEEN_INDIVIDUAL_WORKER_RESTARTS) - Interval in minutes between individual worker restarts (when cluster restart is triggered). By default restarts are not enabled. If restarts are enabled,allWorkersRestartIntervalshould also be set.
spec/dummy/client/vm-renderer.js
Create a file './vm-renderer.js'
import path from 'path';
import { reactOnRailsProVmRenderer } from 'react-on-rails-pro-vm-renderer';
const config = {
  // Save bundles to relative "./tmp/bundles" dir of our app 
  bundlePath: path.resolve(__dirname, './tmp/bundles'), 
  
  // All other values are the defaults, as described above 
};
// Renderer detects a total number of CPUs on virtual hostings like Heroku or CircleCI instead
// of CPUs number allocated for current container. This results in spawning many workers while
// only 1-2 of them really needed.
if (process.env.CI) {
  config.workersCount = 2;
}
reactOnRailsProVmRenderer(config);And add this line to your scripts section of package.json
  "scripts": {
    "start": "echo 'Starting React on Rails Pro VM Renderer.' && node ./vm-renderer.js"
  },yarn start will run the renderer.
For more info on demoing or buying React on Rails Pro, email [email protected].