Last active
December 21, 2015 22:29
-
-
Save narqo/6375881 to your computer and use it in GitHub Desktop.
Test for http request and the globals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'), | |
util = require('util'), | |
port = process.env.PORT || 3014, | |
counter = 1; | |
/* global lang:true */ | |
lang = 'ru'; | |
function onRequest(req, res) { | |
counter += 1; // Oops | |
// user's language is depends on some freaky logic... | |
lang = counter % 2 === 0? 'ru' : 'en'; // Oops | |
console.log(counter); | |
console.log(lang); | |
setTimeout(function() { | |
var tmpl = util.format('We got %d request and the language is set to <b>%s</b>\n', | |
counter, lang); | |
res.writeHead(200, { | |
'Content-Type' : 'text/html' | |
}); | |
res.end(tmpl); | |
}, 3000); | |
} | |
http.createServer(onRequest).listen(port); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
› ((curl "http://localhost:3014" &) ; curl "http://localhost:3014" &) 2> /dev/null | |
We got 3 request and the language is set to <b>en</b> # ← this one should be 2nd with "ru" | |
We got 3 request and the language is set to <b>en</b> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment