11const path = require ( 'path' ) ;
2+
23const { reactOnRailsProNodeRenderer } = require ( 'react-on-rails-pro-node-renderer' ) ;
34
45const { env } = process ;
6+ const parsedConcurrency =
7+ env . NODE_RENDERER_CONCURRENCY != null ? Number ( env . NODE_RENDERER_CONCURRENCY ) : undefined ;
58
69const config = {
710 serverBundleCachePath : path . resolve ( __dirname , '../.node-renderer-bundles' ) ,
811 port : Number ( env . RENDERER_PORT ) || 3800 ,
912 logLevel : env . RENDERER_LOG_LEVEL || 'info' ,
1013
1114 // See value in /config/initializers/react_on_rails_pro.rb
12- password : env . RENDERER_PASSWORD || 'devPassword' ,
15+ password : ( ( ) => {
16+ if ( ! env . RENDERER_PASSWORD && env . NODE_ENV === 'production' ) {
17+ throw new Error ( 'RENDERER_PASSWORD must be set in production' ) ;
18+ }
19+ return env . RENDERER_PASSWORD || 'devPassword' ;
20+ } ) ( ) ,
1321
1422 // Number of Node.js worker threads for SSR rendering
1523 // Set NODE_RENDERER_CONCURRENCY env var to override (e.g., for production tuning)
16- workersCount : env . NODE_RENDERER_CONCURRENCY != null ? Number ( env . NODE_RENDERER_CONCURRENCY ) : 3 ,
24+ workersCount : parsedConcurrency ?? 3 ,
1725
1826 // If set to true, `supportModules` enables the server-bundle code to call a default set of NodeJS modules
1927 // that get added to the VM context: { Buffer, process, setTimeout, setInterval, clearTimeout, clearInterval }.
@@ -34,7 +42,7 @@ const config = {
3442// Renderer detects a total number of CPUs on virtual hostings like Heroku or CircleCI instead
3543// of CPUs number allocated for current container. This results in spawning many workers while
3644// only 1-2 of them really needed.
37- if ( env . CI ) {
45+ if ( env . CI && env . NODE_RENDERER_CONCURRENCY == null ) {
3846 config . workersCount = 2 ;
3947}
4048
0 commit comments