npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-turnout

v0.0.4-alpha

Published

Pre-rendering Single-Page-Application for crawlers.

Downloads

28

Readme

icon expressTurnout NPM version Build Status Coverage Status

Pre-rendering Single-Page-Application for crawlers.

Setup

  1. Install phantomjs 2.0.0 or Build
λ phantomjs -v
# 2.0.0

Or

$ phantomjs -v
# 2.0.0
  1. Install modules
$ npm install express express-turnout --save
  1. Use express-turnout before routing.

Example:

// 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);
});
  1. Add below to <head> in index.html:
<script src="/express-turnout.js"></script>
  1. Finally, Execute window.expressTurnoutRendered() at Timing of Should be read for crawlers.

Example:

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...
})
;

How it works the source code for crawlers?

Add '?escaped_fragment' to URL.

Example:

$ curl http://localhost:59798/?_escaped_fragment_

<html lang="en" ng-app="myApp" class="ng-scope"><head><style type="text/css">@charset "UTF-8";[ng\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak,.ng-hide:not(.ng-hide-animate){display:none !important;}ng\:form{display:block;}</style>
  <meta charset="UTF-8">
  <title>Welcome googlebot!</title>
  <base href="/">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.14/angular-ui-router.js"></script>

  <script src="/express-turnout.js"></script>
  <script>
  //...
  </script>
</head>
<!-- uiView:  --><body ui-view="" class="ng-scope"><h1 class="ng-scope">first</h1><a ui-sref="second" class="ng-scope" href="/second">second</a></body></html>

API

express-turnout(options)

Options

blacklist

Return 403 If matched URL in RegExps.

Default: []

whitelist

Return 403 Unless matched URL in RegExps.

Default: []

timeout

Return 403 if exceeded the time.

Default: 1000 ms

maxBuffer

Return 500 if rendered html is more than the number of bytes.

Default: 1000 ms

ua

Do Pre-rendering If matched UserAgent in RegExps.

Default: ['Googlebot','Twitterbot']

DEBUG=express:turnout

See Debugging Express

Example:

$ 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 <html lang="en" ng-app="myApp" class="ng-scope">...<!-- uiView:  --><body ui-view="" class="ng-scope"><h1 class="ng-scope">second</h1><a ui-sref="first" class="ng-scope" href="">first</a></body></html>

/express-turnout.js

window.expressTurnoutRendered

Finish the Pre-rendering If Execute via express-turnout.

Inspired

prerender-node / AngularJS SEO with Prerender.io | Scotch

License

MIT