Skip to content

Instantly share code, notes, and snippets.

@teone
Created October 29, 2015 15:57
Show Gist options
  • Save teone/a36e231ecf100691301d to your computer and use it in GitHub Desktop.
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.
// 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