Created
December 2, 2017 18:00
-
-
Save erasmo-marin/7495dcd1f1abacecb80b99f4d8fde776 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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