Created
September 12, 2021 10:40
-
-
Save ConorCorp/dad1755aaf617a49557462f13d172da2 to your computer and use it in GitHub Desktop.
Basic browsersync middleware example
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
// 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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
run with
node middleware.js