Skip to content

Instantly share code, notes, and snippets.

@luismoramedina
Created June 14, 2016 11:30
Show Gist options
  • Save luismoramedina/0c4337d23220a1afccef9f2270de3f69 to your computer and use it in GitHub Desktop.
Save luismoramedina/0c4337d23220a1afccef9f2270de3f69 to your computer and use it in GitHub Desktop.
Emulates a heavy nodejs delayed rest service
http = require("http");
function sleep(milliSeconds, callback) {
var startTime = new Date().getTime();
while (new Date().getTime() < startTime + milliSeconds);
}
server = http.createServer(function (request, response) {
console.log(request);
console.log('a request');
var data;
if (request.url === '/sleep') {
sleep(3000);
data = '{"delay" : 3000}';
} else if (request.url === '/') {
data = '{"delay" : 0}';
} else {
data = '{"error" : "true"}';
response.statusCode = 500;
}
response.end(data);
});
server.listen(9000);
console.log("running... on 9000");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment