base-router icon indicating copy to clipboard operation
base-router copied to clipboard

Revisit API for serve

Open shama opened this issue 10 years ago • 2 comments

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.

shama avatar Jun 01 '15 19:06 shama

Still thinking this over but this part likely doesn't belong in this lib and will probably be removed next major.

shama avatar Jun 22 '15 16:06 shama

I would support that. It does require('url') which adds a significant chunk to the bundle.

gmaclennan avatar Jun 23 '16 03:06 gmaclennan