Skip to content

Instantly share code, notes, and snippets.

@isaacs
Forked from hassox/chain-example.js
Created January 11, 2010 06:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save isaacs/274033 to your computer and use it in GitHub Desktop.
Save isaacs/274033 to your computer and use it in GitHub Desktop.
chain
(addCustomHeaders)
(errorHandler)
(deflate)
(route
("/foo", chain(fooApp)()) // the () ends the chain
(/^\/blog\/(.*)/, chain(funkyBlogApp)()) // the () ends the chain
(/^\/static\//, chain
(farFutureExpiresHeader)
(route
(/^js\/(.*)\.js$/, chain
(javascriptHeaders)
(jsmin)) // no (), so fall through
(/^css\/(.*)\.css$/, chain
(cssHeaders)
(cssmin))))) // no (), so fall through
(directoryIndex) // if it's a folder, this does
(fileServer)
()
.listen(8000); // this starts the server.
/(B)---------------
--(A)--* /(D)--| \
\(C)---* --(G)--(H)
\(E)--(F)--/
chain
(A)
(route
("/B", B) // single link, then fallthrough, don't need a chain
("/C", chain
(C)
(route
("/D", chain(D)()) // terminus
("/E", chain(E)(F)))))
(G)
(H)
().listen(8000);
Please note these are a quick brain dump only... (btw I don't see how this syntax works ;) I'm interested to know) Some of these things could be fixed, but I'm not sure about all of them.
*Love the idea of mounting a component as part of a chain, _and_ as a seperate service
*route construction complete immediately. i.e. no option to build the routes and add to them gradually. This will mean users cannot add routes to a component (bad), and that components must know all the routes when the chain is built. No dynamic runtime construction is available.
* Having the router as something different to a link means that the router must be built into chain, and becomes unchangable. By using the router as a link approach, a router is just another link, and multiple routers can be used / interchanged... Also, syntax is fixed, and somewhat immutable after construction.
* No route parameters enabled. Route route parameters from both the url (path segments) and also from some kind of request object (user_agent, domains) are very useful in a router.
* the router becomes responsible for moving the reuqest along a chain. I tend to think of a router as an entry exit hub, passing the request from incomming to outgoing and then standing back.
* router should be able to generate routes. Nested routers should generate the full url's including interperating parameters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment