Created
November 27, 2015 22:49
-
-
Save weeksdev/f8b593d09c7b05816f12 to your computer and use it in GitHub Desktop.
Express NodeJs Implementation Of Escaped Fragment
This file contains hidden or 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
//declarations | |
var express = require('express'); | |
var app = express(); | |
var bodyParser = require('body-parser'); | |
var compress = require('compression'); | |
//catch all get requests and determine if there is an escaped_fragment, if so reroute to a relative folder public/_escaped_fragment_/{}.html | |
//if you have more complex hashes than `#!Something` then you may have to mod this logic to suit your needs. | |
app.get("*", function (req, res, next) { | |
if (req.query._escaped_fragment_) { | |
//pull file from escaped fragments folder and serve it | |
res.sendFile(__dirname + '/public/_escaped_fragment_/' + req.query._escaped_fragment_ + '.html'); | |
} else { | |
//continue down the next express routes and get caught in static files or potentially other routes you have declared | |
next(); | |
} | |
}); | |
//serve static files from public | |
app.use(express.static('public')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment