Skip to content

Latest commit

 

History

History
52 lines (39 loc) · 1.67 KB

node-npm.md

File metadata and controls

52 lines (39 loc) · 1.67 KB

Pre-rendering: Node.js Integration via NPM

This integration will work with any Node.js solution which follows Node's middleware convention, like: express, connect, vanilla Node.js server, and others

Installation

npm install spiderable-middleware --save

Update HTML Markup

To cause the special behavior of web crawlers on JavaScript powered websites use fragment meta tag. Although it's officially deprecated by Google search engine, it's may be used by other search engines and web crawlers. Learn more

<html>
  <head>
    <meta name="fragment" content="!">
    <!-- ... -->
  </head>
  <body>
    <!-- ... -->
  </body>
</html>

Middleware integration

See more detailed examples examples here

'use strict';
import http from 'http';
import Spiderable from 'spiderable-middleware';

const spiderable = new Spiderable({
  rootURL: 'http://example.com',
  auth: 'APIUser:APIPass',
});

const requestListener = function (req, res) {
  spiderable.handler(req, res, function () {
    res.writeHead(200, {'Content-Type': 'text/plain; charset=UTF-8'});
    res.end('Hello vanilla NodeJS!');
  });
};

http.createServer(requestListener).listen(3000);