Created
October 29, 2015 15:57
-
-
Save teone/a36e231ecf100691301d to your computer and use it in GitHub Desktop.
Setup a proxy with gulp and browsersync. Please note that this is not a complete Gulp File, it is just to remember how to set up a proxy.
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
// please note that this is not a complete Gulp File, | |
// it is just to remember how to set up a proxy | |
var httpProxy = require('http-proxy'); | |
var proxy = httpProxy.createProxyServer({ | |
target: 'http://0.0.0.0:9000' | |
}); | |
proxy.on('error', function(error, req, res) { | |
res.writeHead(500, { | |
'Content-Type': 'text/plain' | |
}); | |
console.error('[Proxy]', error); | |
}); | |
gulp.task('browser', function() { | |
browserSync.init({ | |
server: { | |
baseDir: options.src, | |
middleware: function(req, res, next){ | |
console.log(req.url); | |
if(req.url.indexOf('no_hyperlinks') !== -1){ | |
proxy.web(req, res); | |
} | |
else{ | |
next(); | |
} | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment