-
-
Save Mostafa-Samir/8d88882e223a43bbbdef to your computer and use it in GitHub Desktop.
A sample HTTP server application for tutorial here: http://mostafa-samir.github.io/async-recursive-patterns-pt2/
This file contains 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'); | |
var server = http.createServer(function(request, response) { | |
var randomNetworkDelayFactor = Math.floor(Math.random() * 99) + 1; | |
// simulates a random network delay up to one second | |
setTimeout(function() { | |
var request_path = request.url; | |
response.writeHead(200, {"Content-Type": "application/json"}); | |
if(request_path === '/meta/moduleA') { | |
var dataA = JSON.stringify({ | |
"hasDependency": true, | |
"dependency": "moduleB" | |
}); | |
response.end(dataA); | |
} | |
else if(request_path === '/meta/moduleB') { | |
var dataB = JSON.stringify({ | |
"hasDependency": true, | |
"dependency": "moduleC" | |
}); | |
response.end(dataB); | |
} | |
else if(request_path === '/meta/moduleC') { | |
var dataC = JSON.stringify({ | |
"hasDependency": false, | |
}); | |
response.end(dataC); | |
} | |
else { | |
response.end(JSON.stringify({ | |
"err": "NOT FOUND" | |
})); | |
} | |
}, randomNetworkDelayFactor * 10); | |
}); | |
server.listen(8080); | |
console.log("The server is running on http://localhost:8080"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment