MCPcopy Index your code
hub / github.com/codecombat/codecombat / setupCountryRedirectMiddleware

Function setupCountryRedirectMiddleware

server_setup.js:113–131  ·  view source on GitHub ↗
(app, country, host)

Source from the content-addressed store, hash-verified

111};
112
113const 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
133const setupOneSecondDelayMiddleware = function(app) {
134 if(config.slow_down) {

Callers 1

server_setup.jsFile · 0.85

Calls 1

Tested by

no test coverage detected