Skip to content

Instantly share code, notes, and snippets.

@weeksdev
Created November 27, 2015 22:49
Show Gist options
  • Save weeksdev/f8b593d09c7b05816f12 to your computer and use it in GitHub Desktop.
Save weeksdev/f8b593d09c7b05816f12 to your computer and use it in GitHub Desktop.
Express NodeJs Implementation Of Escaped Fragment
//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