Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 7d4e7fe
Merge: cb9fab4 3c0e6d9
Author: eacaps <[email protected]>
Date:   Mon Aug 1 11:46:35 2016 -0400

    Merge branch 'feature/no-request-context' of github.com:eacaps/react_on_rails into feature/no-request-context

commit cb9fab4
Author: eacaps <[email protected]>
Date:   Thu Jul 21 13:23:51 2016 -0400

    allow component rendering in contexts without requests

    allow custom_context even without request

    added broken test

    added fixes to allow actionmailer test to pass

    cleaned up rubocop warnings

    resolved some reviewed suggestions

    updated with proper handles for inMailer

    added inMailer to test

    added inMailer checks for test

    cleaned up rubocop suggestions

    a few final minor tweaks

commit 3c0e6d9
Merge: 5637162 63436ab
Author: eacaps <[email protected]>
Date:   Mon Aug 1 10:44:59 2016 -0400

    Merge branch 'master' into feature/no-request-context

commit 5637162
Author: eacaps <[email protected]>
Date:   Mon Aug 1 10:35:40 2016 -0400

    a few final minor tweaks

commit 63436ab
Merge: b4cdfd2 d694df8
Author: Justin Gordon <[email protected]>
Date:   Sun Jul 31 23:01:59 2016 -1000

    Merge pull request shakacode#491 from samphilipd/master

    Add support for single digit version strings, closes shakacode#489

commit d694df8
Author: Sam Davies <[email protected]>
Date:   Wed Jul 27 10:52:49 2016 +0100

    Add support for single digit version strings, closes shakacode#489

commit b4cdfd2
Author: Justin Gordon <[email protected]>
Date:   Sun Jul 31 21:25:57 2016 -1000

    Update README.md

commit 8824b88
Merge: e449d84 442dcd4
Author: Justin Gordon <[email protected]>
Date:   Sun Jul 31 21:25:35 2016 -1000

    Merge pull request shakacode#503 from markpenovich/master

    fixed spelling error

commit 442dcd4
Author: Mark Penovich <[email protected]>
Date:   Sun Jul 31 23:47:20 2016 -0500

    fixed spelling error in readme

commit e449d84
Merge: 95efecd 8cec9cf
Author: Justin Gordon <[email protected]>
Date:   Sun Jul 31 15:49:11 2016 -1000

    Merge pull request shakacode#497 from shakacode/justin808-skip-docker

    Remove docker from CI tests .travis.yml

commit 95efecd
Merge: 46ecf59 ef08742
Author: Justin Gordon <[email protected]>
Date:   Sun Jul 31 15:48:51 2016 -1000

    Merge pull request shakacode#502 from shakacode/move-contributing-to-top-level

    Move CONTRIBUTING.MD to project top level

commit ef08742
Author: Justin Gordon <[email protected]>
Date:   Sun Jul 31 15:06:11 2016 -1000

    Move CONTRIBUTING.MD to project top level

    This seems to make it show more prominently when making new issues or
    PRs.

commit 46ecf59
Merge: cdb246b a6e35fe
Author: Justin Gordon <[email protected]>
Date:   Sun Jul 31 15:42:20 2016 -1000

    Merge pull request shakacode#479 from shakacode/alleycat-at-git-alexey/replace_symlinks_copy

    * Enhancements to webpack asset preparation
    * Better messages when creating symlinks
    * Updated documentation
    * Enhanced example
    * Support subdirectories with webpack assets
    * Move logic for assets code to service object
    * Using defaults of the env settings or else values for directories and
      regexp can be provided.

commit 8cec9cf
Author: Justin Gordon <[email protected]>
Date:   Fri Jul 29 15:34:10 2016 -1000

    Remove Docker from setup

    * Update .travis.yml
    * Remove Dockerfile_tests and docker-compose.yml

commit a6e35fe
Author: dzirtusss <[email protected]>
Date:   Tue Jul 26 18:43:20 2016 +0300

    Update assets_precompile_spec.rb

    symlink tests with tempfs

commit 07a6e48
Author: Justin Gordon <[email protected]>
Date:   Sun Jul 17 23:23:03 2016 -1000

    Enhancements to webpack asset preparation

    * Better messages when creating symlinks
    * Updated documentation
    * Enhanced example
    * Support subdirectories with webpack assets
    * Move logic for assets code to service object
    * Using defaults of the env settings or else values for directories and
      regexp can be provided.

commit cdb246b
Author: Justin Gordon <[email protected]>
Date:   Sat Jul 30 12:30:33 2016 -1000

    Doc Fixes (shakacode#499)

    * Update node-server-rendering.md
    * Update README.md

commit 1e4c0ed
Author: Justin Gordon <[email protected]>
Date:   Sat Jul 30 11:16:25 2016 -1000

    Update README.md

commit 13f2cf0
Author: Justin Gordon <[email protected]>
Date:   Thu Jul 28 13:38:29 2016 -1000

    Update server-rendering-tips.md (shakacode#494)

    Update server-rendering-tips.md and README.md

commit 0604006
Merge: 8ca86ed e69480a
Author: Justin Gordon <[email protected]>
Date:   Wed Jul 27 22:14:17 2016 -1000

    Merge pull request shakacode#492 from cubadomingo/patch-1

    Fixes typo

commit e69480a
Author: Devin Osorio <[email protected]>
Date:   Wed Jul 27 22:34:13 2016 -0400

    Fixes typo

commit 566d62f
Author: eacaps <[email protected]>
Date:   Mon Jul 25 12:59:44 2016 -0400

    cleaned up rubocop suggestions

commit e24fb9f
Author: eacaps <[email protected]>
Date:   Mon Jul 25 11:28:56 2016 -0400

    added inMailer checks for test

commit eb6e700
Author: eacaps <[email protected]>
Date:   Mon Jul 25 11:14:41 2016 -0400

    added inMailer to test

commit 8d34353
Author: eacaps <[email protected]>
Date:   Mon Jul 25 10:41:35 2016 -0400

    updated with proper handles for inMailer

commit 52f0cbb
Merge: 840bc62 8ca86ed
Author: eacaps <[email protected]>
Date:   Mon Jul 25 10:27:23 2016 -0400

    Merge branch 'master' into feature/no-request-context

commit 8ca86ed
Merge: 9a8b54f 0257cae
Author: Justin Gordon <[email protected]>
Date:   Fri Jul 22 21:35:57 2016 -1000

    Merge pull request shakacode#487 from jooohn/fix/typo-in-readme

    fix(typo) remove duplicated word in readme

commit 0257cae
Author: jooohn <[email protected]>
Date:   Sat Jul 23 13:12:37 2016 +0900

    fix(typo) remove duplicated word in readme

commit 840bc62
Author: eacaps <[email protected]>
Date:   Fri Jul 22 09:57:28 2016 -0400

    resolved some reviewed suggestions

commit 9b958fb
Merge: 6fdb73a 9a8b54f
Author: eacaps <[email protected]>
Date:   Fri Jul 22 09:56:35 2016 -0400

    Merge branch 'master' into feature/no-request-context

commit 9a8b54f
Merge: e6afa98 4890486
Author: Justin Gordon <[email protected]>
Date:   Thu Jul 21 17:42:32 2016 -1000

    Merge pull request shakacode#483 from shakacode/justin808-inaccurate-build-test-message

    Update ensure_assets_compiled.rb

commit 6fdb73a
Author: eacaps <[email protected]>
Date:   Thu Jul 21 16:35:42 2016 -0400

    cleaned up rubocop warnings

commit d99fc36
Author: eacaps <[email protected]>
Date:   Thu Jul 21 14:46:20 2016 -0400

    added fixes to allow actionmailer test to pass

commit 05d3144
Author: eacaps <[email protected]>
Date:   Thu Jul 21 14:31:19 2016 -0400

    added broken test

commit 610906e
Author: eacaps <[email protected]>
Date:   Thu Jul 21 13:25:42 2016 -0400

    allow custom_context even without request

commit 1e9d58c
Author: eacaps <[email protected]>
Date:   Thu Jul 21 13:23:51 2016 -0400

    allow component rendering in contexts without requests

commit 4890486
Author: Justin Gordon <[email protected]>
Date:   Wed Jul 20 19:55:39 2016 -1000

    Update ensure_assets_compiled.rb
  • Loading branch information
eacaps committed Aug 2, 2016
1 parent e6afa98 commit ec97365
Show file tree
Hide file tree
Showing 44 changed files with 687 additions and 298 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ env:

before_install:
- sudo apt-get update
- curl -L https://github.com/docker/compose/releases/download/1.4.0/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
- sudo apt-get install -y xvfb libappindicator1 fonts-liberation
- wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
- sudo dpkg -i google-chrome*.deb
Expand All @@ -34,7 +31,6 @@ install:
- rake dummy_apps
- rake examples
- rake node_package
- docker-compose up lint

before_script:
- "export DISPLAY=:99"
Expand Down
10 changes: 6 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com]

## [Unreleased]

- React on Rails now correctly parses single-digit version strings from package.json [#491](https://github.com/shakacode/react_on_rails/pull/491)

## [6.0.5]
##### Added
- Added better error messages to avoid issues with shared redux stores [#470](https://github.com/shakacode/react_on_rails/pull/470).
Expand All @@ -27,19 +29,19 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com]

## [6.0.0]
##### Breaking Changes
- Added automatic compilation of assets at precompile is now done by ReactOnRails. Thus, you don't need to provide your own assets.rake file that does the precompilation.
- Added automatic compilation of assets at precompile is now done by ReactOnRails. Thus, you don't need to provide your own assets.rake file that does the precompilation.
[#398](https://github.com/shakacode/react_on_rails/pull/398) by [robwise](https://github.com/robwise), [jbhatab](https://github.com/jbhatab), and [justin808](https://github.com/justin808).
- **Migration to v6**
- Do not run the generator again if you've already run it.

- See [shakacode/react-webpack-rails-tutorial/pull/287](https://github.com/shakacode/react-webpack-rails-tutorial/pull/287) for an example of upgrading from v5.

- To configure the asset compliation you can either
1. Specify a `config/react_on_rails` setting for `npm_build_production_command` to be nil to turn this feature off.
2. Specify the script command you want to run to build your production assets, and remove your assets.rake file.

- If you are using the ReactOnRails test helper, then you will need to add the 'config.npm_build_test_command' to your config to tell react_on_rails what command to run when you run rspec.

- See [shakacode/react-webpack-rails-tutorial #287](https://github.com/shakacode/react-webpack-rails-tutorial/pull/287/files) for an upgrade example. The PR has a few comments on the upgrade.

Here is the addition to the generated config file:
Expand Down Expand Up @@ -92,7 +94,7 @@ Here is the addition to the generated config file:
- [Security] Address failure to sanitize console messages when server rendering and displaying in the browser console. See [#366](https://github.com/shakacode/react_on_rails/pull/366) and [#370](https://github.com/shakacode/react_on_rails/pull/370) by [justin808](https://github.com/justin808)

##### Added
- railsContext includes the port number and a boolean if the code is being run on the server or client.
- railsContext includes the port number and a boolean if the code is being run on the server or client.

## [5.1.0] - 2016-04-03
##### Added
Expand Down
4 changes: 3 additions & 1 deletion docs/contributor-info/contributing.md → CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Tips for Contributors
*See [Releasing](./releasing.md) for instructions on releasing.*

* See [docs/contributor-info/Releasing](./docs/contributor-info/releasing.md) for instructions on releasing.
* See other docs in [docs/contributor-info](./docs/contributor-info)

## Sumary

Expand Down
12 changes: 0 additions & 12 deletions Dockerfile_tests

This file was deleted.

152 changes: 22 additions & 130 deletions README.md

Large diffs are not rendered by default.

38 changes: 21 additions & 17 deletions app/helpers/react_on_rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,29 +341,33 @@ def initialize_redux_stores

# This is the definitive list of the default values used for the rails_context, which is the
# second parameter passed to both component and store generator functions.
# rubocop:disable Metrics/AbcSize
def rails_context(server_side:)
@rails_context ||= begin
# Using Addressable instead of standard URI to better deal with
# non-ASCII characters (see https://github.com/shakacode/react_on_rails/pull/405)
uri = Addressable::URI.parse(request.original_url)
# uri = Addressable::URI.parse("http://foo.com:3000/posts?id=30&limit=5#time=1305298413")

result = {
# URL settings
href: request.original_url,
location: "#{uri.path}#{uri.query.present? ? "?#{uri.query}" : ''}",
scheme: uri.scheme, # http
host: uri.host, # foo.com
port: uri.port,
pathname: uri.path, # /posts
search: uri.query, # id=30&limit=5

inMailer: controller.present? && controller.is_a?(ActionMailer::Base),
# Locale settings
i18nLocale: I18n.locale,
i18nDefaultLocale: I18n.default_locale,
httpAcceptLanguage: request.env["HTTP_ACCEPT_LANGUAGE"]
i18nDefaultLocale: I18n.default_locale
}

if request.present?
# Using Addressable instead of standard URI to better deal with
# non-ASCII characters (see https://github.com/shakacode/react_on_rails/pull/405)
uri = Addressable::URI.parse(request.original_url)
# uri = Addressable::URI.parse("http://foo.com:3000/posts?id=30&limit=5#time=1305298413")

result.merge!(
# URL settings
href: request.original_url,
location: "#{uri.path}#{uri.query.present? ? "?#{uri.query}" : ''}",
scheme: uri.scheme, # http
host: uri.host, # foo.com
port: uri.port,
pathname: uri.path, # /posts
search: uri.query, # id=30&limit=5
httpAcceptLanguage: request.env["HTTP_ACCEPT_LANGUAGE"]
)
end
if ReactOnRails.configuration.rendering_extension
custom_context = ReactOnRails.configuration.rendering_extension.custom_context(self)
result.merge!(custom_context) if custom_context
Expand Down
11 changes: 0 additions & 11 deletions docker-compose.yml

This file was deleted.

132 changes: 125 additions & 7 deletions docs/additional-reading/node-server-rendering.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
## Node Server Rendering
# Node.js for Server Rendering

### Warning: this is an experimental feature
Node.js can be used as the backend for server-side rendering instead of [execJS](https://github.com/rails/execjs). Before you try this, consider the tradeoff of extra complexity with your deployments versus *potential* performance gains. We've found that using ExecJS with [mini_racer](https://github.com/discourse/mini_racer) to be "fast enough" so far. That being said, we've heard of other large websites using Node.js for better server rendering performance.

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 your configured server_bundle_js file and
then executes javascript to render the component inside its environment. The communication between rails and node occurs
via socket (`client/node/node.sock`)
If you're serious about this comparing Node.js versus execJS/mini_racer, then [get in touch](mailto:[email protected])! We can definitely collaborate with you on refining this solution. However, please try out these instructions first.

## Setup of React on Rails with Node.js Server Rendering
**Warning: this is an experimental feature.**

To do this you need to add a few files and then configure react_on_rails to use NodeJS. Here are the relevant files to add.

Node server rendering allows you to use separate NodeJS process as a renderer. The process loads your configured server_bundle_js file and then executes javascript to render the component inside its environment. The communication between rails and node occurs
via a socket (`client/node/node.sock`)

### Getting started

### Configuration

#### Update the React on Rails Initializer

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
```ruby
# app/config/initializers/react_on_rails.rb
config.server_render_method = "NodeJS"
```

You need to configure the name of the server bundle in two places:

Expand All @@ -26,3 +38,109 @@ You need to configure the name of the server bundle in two places:
# not affect performance.
config.server_bundle_js_file = "webpack-bundle.js"
```

And in `client/node/package.json`

```javascript
// client/node/package.json
{
"name": "react_on_rails_node",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./server.js -s webpack-bundle.js"
},
"dependencies": {
}
}
```

And you'll need this file: `client/node/server.js`

```javascript
// client/node/server.js
var net = require('net');
var fs = require('fs');

var bundlePath = '../../app/assets/webpack/';
var bundleFileName = 'webpack-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();
});

```

Loading

0 comments on commit ec97365

Please sign in to comment.