Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History

readme.md

Outline

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.

Techniques used in the examples

Create a File Server

var mySite = new lightnode.FileServer("/home/web/mysite.com")

Send a request to be processed by a server

mySite.receiveRequest(request, response)

Delegate to another server when a request is received

mySite.delegateRequest = function(req, resp) {
	return someOtherServer
}

Create or get a child server

mySite.getChild('images')

Specify a special constructor used to create any child servers

mySite.constructChild = function(name) {
	return new MyServerType()
}

Delegate to an existing child server

// 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')
Morty Proxy This is a proxified and sanitized view of the page, visit original site.