Skip to content
This repository has been archived by the owner on Jan 22, 2020. It is now read-only.

Commit

Permalink
on the server side, when the docType is empty, attach the script to t…
Browse files Browse the repository at this point in the history
…he end of the rendered string
  • Loading branch information
samsel committed Nov 6, 2015
1 parent 9000ada commit 4a40525
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ language: node_js
node_js:
- "0.12"
- "0.10"
- "iojs-v1.1.0"
- "4.0"
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.6.0 (Nov 06 2015)

* make the render root configurable (https://github.com/paypal/react-engine/issues/68)

## 2.5.0 (Oct 29 2015)

* Throw an error only if peer dependency is not installed and is really required (https://github.com/paypal/react-engine/pull/98)
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

### Install
```sh
# react-engine needs to be installed along side react, express and optionally react-router
npm install react-engine@2 express [email protected] [email protected] --save
# In your express app, react-engine needs to be installed along side react and optionally react-router
npm install react-engine@2 [email protected] [email protected] --save
```

### Usage On Server Side
Expand Down Expand Up @@ -76,7 +76,8 @@ The options object can contain properties from [react router's create configurat

Additionally, it can contain the following **optional** properties,

- `docType`: <String> - string that can be used as a doctype (_Default: `<!DOCTYPE html>`_)
- `docType`: <String> - a string that can be used as a doctype (_Default: `<!DOCTYPE html>`_).
(docType might not make sense if you are rendering partials/sub page components, in that case you can pass and empty string as docType)
- `routesFilePath`: <String> - path for the file that contains the react router routes.
react-engine uses this behind the scenes to reload the routes file in
cases where [express's app property](http://expressjs.com/api.html#app.set) `view cache` is false, this way you don't need to restart the server every time a change is made in the view files or routes file.
Expand Down Expand Up @@ -125,10 +126,11 @@ var data = client.data();
Pass in a JavaScript object as options to the react-engine's client boot function.
The options object can contain properties from [react router's create configuration object](http://rackt.github.io/react-router/#Router.create).
Additionally, it should contain the following **required** property,
Additionally, it can contain the following properties,
- `viewResolver` : <Function> - a function that react-engine needs to resolve the view file.
- `viewResolver` : **required** - <Function> - a function that react-engine needs to resolve the view file.
an example of the viewResolver can be [found here](https://github.com/paypal/react-engine/blob/ecd27b30a9028d3f02b8f8e89d355bb5fc909de9/examples/simple/public/index.js#L29).
- `mountNode` : **optional** - <HTMLDOMNode> - supply a HTML DOM Node to mount the server rendered component in the case of partial/non-full page rendering.
### Data for component rendering
The actual data that gets fed into the component for rendering is the `renderOptions` object that [express generates](https://github.com/strongloop/express/blob/2f8ac6726fa20ab5b4a05c112c886752868ac8ce/lib/application.js#L535-L588).
Expand Down
11 changes: 10 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,16 @@ exports.create = function create(createOptions) {

// state (script) injection
var script = format(TEMPLATE, Config.client.markupId, JSON.stringify(data));
html = html.replace('</body>', script + '</body>');

if (createOptions.docType === '') {
// if the `docType` is empty, the user did not want to add a docType to the rendered component,
// which means they might not be rendering a full page with `html` and `body` tags
// so attach the script tag to just the end of the generated html string
html += script;
}
else {
html = html.replace('</body>', script + '</body>');
}

return done(null, html);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-engine",
"version": "2.5.0",
"version": "2.6.0",
"description": "a composite render engine for express apps to render both plain react views and react-router views",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 4a40525

Please sign in to comment.