Skip to content

Instantly share code, notes, and snippets.

@anandanand84
Created May 5, 2016 23:17
Show Gist options
  • Save anandanand84/fe9487b6ec15fec2c6e9d4de30d6a3e0 to your computer and use it in GitHub Desktop.
Save anandanand84/fe9487b6ec15fec2c6e9d4de30d6a3e0 to your computer and use it in GitHub Desktop.
Browsersync with proxy
/**
* Created by AAravindan on 5/5/16.
*/
var gulp = require('gulp');
var browserSync = require('browser-sync');
gulp.task('serve', ['styles', 'elements'], function() {
var url = require('url');
var proxy = require('proxy-middleware');
var proxyOptions = url.parse('http://localhost:8421/api');
proxyOptions.route = '/api';
//var historyMiddleWare = historyApiFallback({
// verbose : true,
// logger : console.log.bind(console),
// index : "/index.html",
// htmlAcceptHeaders: ["text/html", "application/xhtml+xml"],
// rewrites: [
// { from: /\/decision.*/, to: "/decision/index.html" },
// { from: /\/admin.*/, to: "/admin/index.html" },
// { from: /\/procurement.*/, to: "/procurement/index.html" }
// ]
//});
browserSync({
port: 5001,
notify: false,
logPrefix: 'PSK',
snippetOptions: {
rule: {
match: '<span id="browser-sync-binding"></span>',
fn: function (snippet) {
return snippet;
}
}
},
// Run as an https by uncommenting 'https: true'
// Note: this uses an unsigned certificate which on first access
// will present a certificate warning in the browser.
// https: true,
server: {
baseDir: ['.tmp', 'app'],
middleware: [proxy(proxyOptions)]
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment