(app, country, host)
| 111 | }; |
| 112 | |
| 113 | const setupCountryRedirectMiddleware = function(app, country, host) { |
| 114 | if (country == null) { country = 'china'; } |
| 115 | if (host == null) { host = 'cn.codecombat.com'; } |
| 116 | const hosts = host.split(/;/g); |
| 117 | const shouldRedirectToCountryServer = function(req) { |
| 118 | let left; |
| 119 | const reqHost = ((left = req.hostname != null ? req.hostname : req.host) != null ? left : '').toLowerCase(); // Work around express 3.0 |
| 120 | return (req.country === country) && !Array.from(hosts).includes(reqHost) && (reqHost.indexOf(config.unsafeContentHostname) === -1); |
| 121 | }; |
| 122 | |
| 123 | return app.use(function(req, res, next) { |
| 124 | if (shouldRedirectToCountryServer(req) && hosts.length) { |
| 125 | res.writeHead(302, {"Location": 'http://' + hosts[0] + req.url}); |
| 126 | return res.end(); |
| 127 | } else { |
| 128 | return next(); |
| 129 | } |
| 130 | }); |
| 131 | }; |
| 132 | |
| 133 | const setupOneSecondDelayMiddleware = function(app) { |
| 134 | if(config.slow_down) { |
no test coverage detected