2015-07-20 18:54:30 -04:00
|
|
|
var onHeaders = require('on-headers');
|
|
|
|
var proxy = require('proxy-middleware');
|
|
|
|
var url = require('url');
|
|
|
|
|
2014-12-05 19:26:30 -05:00
|
|
|
module.exports = function(gulp, plugins, config) {
|
|
|
|
return function() {
|
|
|
|
plugins.connect.server({
|
2015-07-20 18:54:30 -04:00
|
|
|
root: [__dirname + '/../../' + config.path],
|
2014-12-22 20:50:10 -05:00
|
|
|
port: config.port,
|
2014-12-05 19:26:30 -05:00
|
|
|
livereload: false,
|
2015-04-21 13:09:58 -04:00
|
|
|
open: false,
|
|
|
|
middleware: function(connect, opt) {
|
2015-07-20 18:54:30 -04:00
|
|
|
config.proxies = config.proxies || [];
|
|
|
|
var middlewares =
|
|
|
|
config.proxies.map(function(entry) { return makeProxy(entry.route, entry.url); });
|
|
|
|
middlewares.push(connect.favicon());
|
|
|
|
// pub serve can't give the right content-type header for jsonp requests
|
|
|
|
// so we must turn off Chromium strict MIME type checking
|
|
|
|
// see https://github.com/angular/angular/issues/3030#issuecomment-123453168
|
|
|
|
middlewares.unshift(stripHeader('x-content-type-options'));
|
|
|
|
return middlewares;
|
2015-04-21 13:09:58 -04:00
|
|
|
}
|
2016-02-25 16:39:02 -05:00
|
|
|
});
|
2014-12-05 19:26:30 -05:00
|
|
|
};
|
|
|
|
};
|
2015-07-20 18:54:30 -04:00
|
|
|
|
|
|
|
function makeProxy(route, urlParam) {
|
|
|
|
var options = url.parse(urlParam);
|
|
|
|
options.route = route;
|
|
|
|
return proxy(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
function stripHeader(toStrip) {
|
|
|
|
return function(req, res, next) {
|
|
|
|
onHeaders(res, function onHeaders() {
|
|
|
|
res.removeHeader(toStrip);
|
|
|
|
});
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
}
|