baseprime / grapnel

The smallest JavaScript router with named parameters, HTML5 pushState, and middleware support
http://grapnel.js.org
468 stars 40 forks source link

Allowing to have multiple GrapnelServer instances #61 #65

Closed ilearnio closed 6 years ago

ilearnio commented 8 years ago

This is primarily for server side. When a new instance of router is created and .start() is fired the grapnel-server will now push the very first serverMiddleware into a new router.rootStack property instead of Grapnel.CallStack.global which is shared between instances

ilearnio commented 8 years ago

I had to also fix detection of the environment in this.options.env because Object.keys(root).length === 0 was not doing it properly when 2 or more instances of router are running. Since root._pathname was specified when running first instance Object.keys(root).length become 1 and for the next instance the expression started to return "client" (when on the server side)