4game-server
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -7,4 +7,6 @@ /** | ||
var https = require('https'); | ||
var parseUrl = require('url').parse; | ||
var extend = require('xtend'); | ||
const rewriteFiles = [ | ||
var rewriteFiles = [ | ||
'/r/js/requirejs-lookup.js', | ||
@@ -22,6 +24,4 @@ '/js/requirejs-external.js' | ||
return function(req, res, next) { | ||
var url = req.url.split('?')[0] | ||
if (rewriteFiles.indexOf(url) !== -1 || /^\/(packages|launcher|c\/_favicons|c\/home)\//.test(url)) { | ||
proxy(host + req.url, res, options); | ||
if (shouldProxyUrl(req.url)) { | ||
proxy(host + req.url, req.headers, res, options); | ||
} else { | ||
@@ -33,4 +33,9 @@ next(); | ||
function proxy(url, res, options) { | ||
return https.get(url, function(pres) { | ||
function proxy(url, headers, res, options) { | ||
var reqOptions = parseUrl(url); | ||
reqOptions.headers = extend(headers || {}); | ||
delete reqOptions.headers.host; | ||
reqOptions.headers.connection = 'close'; | ||
return https.get(reqOptions, function(pres) { | ||
res.writeHead(pres.statusCode, pres.headers); | ||
@@ -44,2 +49,12 @@ pres.pipe(res); | ||
}); | ||
} | ||
function shouldProxyUrl(url) { | ||
if (typeof url === 'string') { | ||
url = parseUrl(url, true); | ||
} | ||
return rewriteFiles.indexOf(url.pathname) !== -1 | ||
|| /^\/(packages|launcher|c\/_favicons|c\/home)\//.test(url.pathname) | ||
|| (url.query && 'popupWidget' in url.query); | ||
} |
{ | ||
"name": "4game-server", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"bin": { | ||
@@ -5,0 +5,0 @@ "4game-server": "bin/4game-server" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13855
232