Pre-rendering Single-Page-Application for crawlers.
npm install express-turnout> Pre-rendering Single-Page-Application for crawlers.
1. Install phantomjs 2.0.0
or Build
```
λ phantomjs -v
# 2.0.0
Or
`bash`
$ phantomjs -v
# 2.0.0
2. Install modules
`bash`
$ npm install express express-turnout --save
3. Use express-turnout before routing.
Example:
`js
// Environment
var port= 59798;
// Dependencies
var express= require('express');
var turnout= require('express-turnout');
// Setup express
var app= express();
app.use(turnout());
app.use(function(req, res) {
res.sendFile(__dirname + '/index.html');
});
app.listen(port, function() {
console.log('listening at %s', port);
});
`
4. Add below to <head> in index.html:
`html`
5. Finally, Execute window.expressTurnoutRendered() at Timing of Should be read for crawlers.
Example:
`js`
angular.module('myApp',['ui.router'])
.run(function($rootScope,$window){
$rootScope.$on('$viewContentLoaded',function(){
var renderedTemplate= document.body.innerHTML.trim().length>0
if(renderedTemplate){
$window.expressTurnoutRendered();
}
});
})
.config(function($stateProvider){
// states...
})
;
> * Spec - expressTurnout
> * Demo - http://turnout.berabou.me
Example:
`bash
$ curl http://localhost:59798/?_escaped_fragment_
API
express-turnout(options)
$3
#### blacklist
[Return 403 If matched URL in RegExps.][1]Default:
[]####
whitelist
[Return 403 Unless matched URL in RegExps.][2]Default:
[]####
timeout
[Return 403 if exceeded the time.][3]Default:
1000 ms####
maxBuffer
[Return 500 if rendered html is more than the number of bytes.][4]Default:
1000 ms####
ua
[Do Pre-rendering If matched UserAgent in RegExps.][5]Default:
['Googlebot','Twitterbot'][1]: ./test/options.spec.coffee#L17
[2]: ./test/options.spec.coffee#L76
[3]: ./test/options.spec.coffee#L137
[4]: ./test/options.spec.coffee#L163
[5]: ./test/options.spec.coffee#L189
DEBUG=express:turnout
> See Debugging ExpressExample:
`bash
$ curl -A Googlebot http://localhost:59798/second$ DEBUG=express:turnout node test/examples/angular-ui-router
express:turnout new Turnout +0ms {"ua":["Googlebot","Twitterbot"],"blacklist":[],"whitelist":[],"timeout":1000,"eventName":"expressTurnoutRendered"}
express:turnout [ 'Googlebot', index: 0, input: 'Googlebot' ] +1m isBot Googlebot
express:turnout Render http://localhost:59798/second? Limit by 1000ms +2ms
express:turnout Rendered +298ms ...second
first
``License
===
[MIT][License]
[License]: 59naga.mit-license.org
[.svg]: https://cdn.rawgit.com/59naga/express-turnout/master/.svg
[npm-image]:https://img.shields.io/npm/v/express-turnout.svg?style=flat-square
[npm]: https://npmjs.org/package/express-turnout
[travis-image]: http://img.shields.io/travis/59naga/express-turnout.svg?style=flat-square
[travis]: https://travis-ci.org/59naga/express-turnout
[coveralls-image]: http://img.shields.io/coveralls/59naga/express-turnout.svg?style=flat-square
[coveralls]: https://coveralls.io/r/59naga/express-turnout?branch=master