Skip to content

Instantly share code, notes, and snippets.

@erasmo-marin
Created December 2, 2017 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erasmo-marin/7495dcd1f1abacecb80b99f4d8fde776 to your computer and use it in GitHub Desktop.
Save erasmo-marin/7495dcd1f1abacecb80b99f4d8fde776 to your computer and use it in GitHub Desktop.
import detector from "spider-detector";
import url from "url";
app.use(detector.middleware());
app.get("*", function(req, res, next) {
//we only serve static snapshots to spiders
if(!req.isSpider() ) {
next();
return;
}
let path = url.parse(req.originalUrl).pathname;
if(path = "/")
path = "/index";
//if the files are in the cache folder:
res.sendFile(`./cache/${path}.html`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment