DenisFrezzato / hyper-ts

Type safe middleware architecture for HTTP servers
https://denisfrezzato.github.io/hyper-ts/
MIT License
393 stars 18 forks source link

support koa as well as express #6

Closed leemhenson closed 6 years ago

leemhenson commented 6 years ago

Hi Giulio

What do you think about supporting multiple server libs? We use http://koajs.com/ rather than express, but their apis are very similar. I've done a simple split via Conn, ExpressConn and KoaConn. The tests all pass but I haven't actually run it in anger yet. I wanted to post it up here to get any feedback you might have.

gcanti commented 6 years ago

Hi!

What do you think about supporting multiple server libs?

It would be really nice, let me read the code carefully and then I'll post some comments

gcanti commented 6 years ago

@leemhenson This is awesome. Basically, excluding the router, you can migrate from express to koa (or the other way around) just by swapping the toRequestHandler function, right?

gcanti commented 6 years ago

I was thinking.. MiddlewareTask.toRequestHandler looks useless now that we have a toRequestHandler function is each adapter, and it just calls eval on the middleware, what if we get rid of it?

gcanti commented 6 years ago

Oh wait, expanding on toRequestHandler there's a problem: each adapter has a hard dependency on MiddlewareTask, we should try to remove it (you are free to write your interpreter, for example one that uses bluebird or funfix's Future under the hood instead of Promise)

gcanti commented 6 years ago

expanding on toRequestHandler there's a problem

@leemhenson I propose to

leemhenson commented 6 years ago

I've made those changes. I agree with the toRequestHandler changes, it was just a load of indirection for no real gain.

gcanti commented 6 years ago

@leemhenson Thanks! Last thing before merging, could you please move the examples out of src? Perhaps a top level folder examples?

leemhenson commented 6 years ago

I've tidied up a smidge more.

gcanti commented 6 years ago

@leemhenson Released in the next channel if you want to try it out

npm i hyper-ts@next # v0.2.0-dev.20180126