base-router
base-router copied to clipboard
Revisit API for serve
Currently .serve() returns a middleware but that makes it a little difficult if you want to integrate with other middleware. Such as:
var useBaseRouter = app.router.serve(function (page, data) {
app.render(page, data)
this.response.writeHead(200, { 'Content-Type': 'text/html' })
this.response.end(toHTML(app.element.vtree))
})
require('http').createServer(function (req, res) {
if (req.url == 'something else') res.end('Error!')
else useBaseRouter(req, res)
}).listen(1337)
Also the context with this.response and this.request is a little awkward.
Still thinking this over but this part likely doesn't belong in this lib and will probably be removed next major.
I would support that. It does require('url') which adds a significant chunk to the bundle.