-
-
Notifications
You must be signed in to change notification settings - Fork 630
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update heroku-deployment.md (+43 squashed commits)
Squashed commits: [15d3513] Update README.md Fix links to installation-overview [24a11c2] Update README.md [73b5bdf] added babel runtime to root package.json [3f94443] Moved api and generator docs to separate folders go keep readme cleaner. [d2164a8] bugfix: execJS timeout [03c5d0a] no message [5785997] Update PROJECTS.md [1e38e34] Extracts Options for react_component helper [7bd0f94] Update build:client in generator to correctly have closing parenthesis [e0775b7] linters [f7e3d27] travis [e8e4f7d] travis [adbf2b9] added docs [9a00d54] added node process startup [2b1f619] added node process startup [4b3e046] fixed node server [7f2dc65] no message [c663eaf] no message [404c282] travis [4db1366] travis [114a40d] travis [8c170c3] travis [41aeac3] travis [274ed74] new travis test [135dc29] new travis [0ae3113] minor fixes [e77804a] travis [ed911be] minor fixes [f91350d] small fixes [3d4f262] added benchmark test [c2c3675] added config [6812e13] node generator [8ba518d] added node [c4dad1e] new travis [1338026] minor fixes [6d9c23c] travis [808573e] minor fixes [4586800] small fixes [0202cc3] added benchmark test [ab50b77] added config [ed82bc7] node generator [16a018e] added node [db5914b] Fix file exists check for server bundle, which returns true for a dir. (NOTE: Similar bugs may exist elsewhere in the code.)
- Loading branch information
Showing
15 changed files
with
401 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## Node Server Rendering | ||
|
||
The default server rendering exploits ExecJS to render react components. | ||
Node server rendering allows you to use separate NodeJS process as a renderer. The process loads server-bundle.js and | ||
then executes javascript to render the component inside its environment. The communication between rails and node occurs | ||
via socket (`client/node/node.sock`) | ||
|
||
### Getting started | ||
|
||
To use node process just set `server_render_method = "NodeJS"` in `config/initializers/react_on_rails.rb`. To change back | ||
to ExecJS set `server_render_method = "ExecJS"` | ||
|
||
### Configuration | ||
|
||
To change the name of server bundle adjust npm start script in `client/node/package.json` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
web: rails s | ||
client: sh -c 'rm app/assets/webpack/* || true && cd client && npm run build:dev:client' | ||
<%- if options.server_rendering? %>server: sh -c 'cd client && npm run build:dev:server'<%- end %> | ||
<%- if options.server_rendering? %> | ||
server: sh -c 'cd client && npm run build:dev:server' | ||
node: sh -c 'cd client/node && npm start' | ||
<%- end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
lib/generators/react_on_rails/templates/base/base/lib/tasks/load_test.rake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace :load_test do | ||
desc "Load test with apache benchmark" | ||
task :run, [:url, :count] do |_, args| | ||
url = args[:url] || "http://localhost:3000/hello_world" | ||
count = args[:count] || 500 | ||
system("ab -c 10 -n #{count} #{url}") | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
lib/generators/react_on_rails/templates/base/server_rendering/client/node/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "react_on_rails_node", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"start": "node ./server.js -s server-bundle.js" | ||
}, | ||
"dependencies": { | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
lib/generators/react_on_rails/templates/base/server_rendering/client/node/server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
var net = require('net'); | ||
var fs = require('fs'); | ||
|
||
var bundlePath = '../../app/assets/webpack/'; | ||
var bundleFileName = 'server-bundle.js'; | ||
|
||
var currentArg; | ||
|
||
function Handler() { | ||
this.queue = []; | ||
this.initialized = false; | ||
} | ||
|
||
Handler.prototype.handle = function (connection) { | ||
var callback = function () { | ||
connection.setEncoding('utf8'); | ||
connection.on('data', (data)=> { | ||
console.log('Processing request: ' + data); | ||
var result = eval(data); | ||
connection.write(result); | ||
}); | ||
}; | ||
|
||
if (this.initialized) { | ||
callback(); | ||
} else { | ||
this.queue.push(callback); | ||
} | ||
}; | ||
|
||
Handler.prototype.initialize = function () { | ||
console.log('Processing ' + this.queue.length + ' pending requests'); | ||
var callback; | ||
while (callback = this.queue.pop()) { | ||
callback(); | ||
} | ||
|
||
this.initialized = true; | ||
}; | ||
|
||
var handler = new Handler(); | ||
|
||
process.argv.forEach((val) => { | ||
if (val[0] == '-') { | ||
currentArg = val.slice(1); | ||
return; | ||
} | ||
|
||
if (currentArg == 's') { | ||
bundleFileName = val; | ||
} | ||
}); | ||
|
||
try { | ||
fs.mkdirSync(bundlePath); | ||
} catch (e) { | ||
if (e.code != 'EEXIST') throw e; | ||
} | ||
|
||
fs.watchFile(bundlePath + bundleFileName, (curr) => { | ||
if (curr && curr.blocks && curr.blocks > 0) { | ||
if (handler.initialized) { | ||
console.log('Reloading server bundle must be implemented by restarting the node process!'); | ||
return; | ||
} | ||
|
||
require(bundlePath + bundleFileName); | ||
console.log('Loaded server bundle: ' + bundlePath + bundleFileName); | ||
handler.initialize(); | ||
} | ||
}); | ||
|
||
var unixServer = net.createServer(function (connection) { | ||
handler.handle(connection); | ||
}); | ||
|
||
unixServer.listen('node.sock'); | ||
|
||
process.on('SIGINT', () => { | ||
unixServer.close(); | ||
process.exit(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.