The examples in the delegation folder represent the preferred usage. The examples directly in this folder are simpler examples and used custom route logic instead of the delegation system, they are therefore useful if just want to see how to the server integrates with node and how you would usually do something in node, beginners to node might want to start there, as well advanced users that would like to compare the difference.
var mySite = new lightnode.FileServer("/home/web/mysite.com")
mySite.receiveRequest(request, response)
mySite.delegateRequest = function(req, resp) {
return someOtherServer
}
mySite.getChild('images')
mySite.constructChild = function(name) {
return new MyServerType()
}
// the server will automatically look for a child server for a request,
// you can control what the name it looks for the child server under.
mySite.getChildName = function(req) {
if (req.url.startsWith('images'))
return 'images'
else if (req.url.startsWith('posts'))
return 'posts'
}
// any child server that is found under the name will be delegated to,
// if it doesn't exist then no delegation is done and the server handles the request itself.
// so there is no need to do anything else except
// create the child servers before any requests come in
mySite.getChild('images')
mySite.getChild('posts')