Skip to content

Instantly share code, notes, and snippets.

@singleseeker
Created November 21, 2016 01:33
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 singleseeker/e038bdaadce7f7f82896510ffd85f47e to your computer and use it in GitHub Desktop.
Save singleseeker/e038bdaadce7f7f82896510ffd85f47e to your computer and use it in GitHub Desktop.
browsersync api post .
middleware: [
{
route: "/api",
handle: function (req, res, next) {
var url = req.url;
var filename = __dirname + '/api' + url;
if (url.indexOf('.json') > -1 && fs.existsSync(filename)) {
var contents = fs.readFileSync(filename, {
encoding: 'utf8'
});
res.end(contents);
} else {
next();
}
}
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment