Skip to content

Instantly share code, notes, and snippets.

@ConorCorp
Created September 12, 2021 10:40
Show Gist options
  • Save ConorCorp/dad1755aaf617a49557462f13d172da2 to your computer and use it in GitHub Desktop.
Save ConorCorp/dad1755aaf617a49557462f13d172da2 to your computer and use it in GitHub Desktop.
Basic browsersync middleware example
// require the module as normal
var bs = require("browser-sync").create();
// .init starts the server
bs.init({
files: "dist/css/*.css, dist/js/*.js, **/*.html, !node_modules/**/*.html",
server: true,
browser: "firefox",
middleware: function(req, res, next) {
console.log(req.url)
if (req.method.toUpperCase() == 'POST')
console.log("I'm in a POST req!")
next();
}
});
// Now call methods on bs instead of the
// main browserSync module export
bs.reload("*.html");
@ConorCorp
Copy link
Author

run with node middleware.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment