react-collider
Advanced tools
Comparing version
@@ -6,3 +6,6 @@ 'use strict'; | ||
Router = require('react-router'), | ||
runRouter = require('./runRouter') | ||
merge = require('ramda').merge, | ||
runRouter = require('./runRouter'), | ||
performance = require('./performance'), | ||
log = require('./log') | ||
@@ -18,10 +21,17 @@ /** | ||
// Server side rendering | ||
var returnResponse = function(res, Handler, data) { | ||
var content = React.renderToString(React.createElement(Handler, {data: cleanData(data)})), | ||
html = '<!DOCTYPE html>' + content | ||
res.end(html) | ||
var defaultOptions = { | ||
log: false | ||
} | ||
module.exports.server = function(routes) { | ||
module.exports.server = function(routes, options) { | ||
options = merge(defaultOptions, options) | ||
// Server side rendering | ||
var returnResponse = function(res, Handler, data, perfInstance) { | ||
var content = React.renderToString(React.createElement(Handler, {data: cleanData(data)})), | ||
html = '<!DOCTYPE html>' + content | ||
options.log && log(options.log, 'perf', perfInstance()) | ||
res.end(html) | ||
} | ||
return function (req, res, next) { | ||
@@ -40,4 +50,6 @@ if (req.method !== 'GET' && req.method !== 'HEAD') { | ||
var perfInstance = performance(reqPath) | ||
runRouter(routes, reqPath, function(Handler, data) { | ||
returnResponse(res, Handler, data) | ||
returnResponse(res, Handler, data, perfInstance) | ||
}) | ||
@@ -44,0 +56,0 @@ } |
{ | ||
"name": "react-collider", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"description": "Express middleware for isomorphic express + react apps", | ||
"main": "lib/index.js", | ||
"main": "index.js", | ||
"repository": { | ||
@@ -31,4 +31,3 @@ "type": "git", | ||
"test": "./node_modules/.bin/mocha", | ||
"jshint": "./node_modules/.bin/jshint lib", | ||
"start": "node test.js" | ||
"jshint": "./node_modules/.bin/jshint lib" | ||
}, | ||
@@ -35,0 +34,0 @@ "tags": [ |
@@ -40,2 +40,14 @@ # React-collider [](http://travis-ci.org/dailymotion/react-collider) | ||
#### Logging | ||
You can have informations in a log file: | ||
```javascript | ||
// logs to react-collider.log | ||
app.use(collider(routes, {log: true})) | ||
// logs to a custom file path | ||
app.use(collider(routes, {log: path.join(__dirname, 'server.log')})) | ||
``` | ||
### Client side | ||
@@ -129,3 +141,3 @@ | ||
fetchData: function() { | ||
return provider(this, 'http://api.dailymotion.com/videos?fields=id,title', {once: true}) | ||
return provider(this, 'https://api.dailymotion.com/videos?fields=id,title', {once: true}) | ||
} | ||
@@ -132,0 +144,0 @@ } |
25735
9.26%23
15%538
12.08%165
7.84%5
25%