diff --git a/lib/proxy.js b/lib/proxy.js index 1d876c0..1ca98bf 100755 --- a/lib/proxy.js +++ b/lib/proxy.js @@ -190,6 +190,7 @@ ReverseProxy.prototype.setupHttpProxy = function (proxy, websocketsUpgrade, log, var httpServerModule = opts.serverModule || http; var server = (this.server = httpServerModule.createServer(function (req, res) { var src = _this._getSource(req); + res = allowCORS(res, opts); _this ._getTarget(src, req, res) .bind(_this) @@ -771,6 +772,14 @@ function redirectToHttps(req, res, target, ssl, log) { res.end(); } +function allowCORS(res, opts){ + if(opts.cors && opts.cors.allow === true){ + res.setHeader("Access-Control-Allow-Origin", "*"); + res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); + } + return res +} + function startsWith(input, str) { return ( input.slice(0, str.length) === str && (input.length === str.length || input[str.length] === '/')