koajs / koa

Expressive middleware for node.js using ES2017 async functions
https://koajs.com
MIT License
35.11k stars 3.22k forks source link

[feat] Could a listen() shortcut function be added also for http2? #1756

Closed crystalfp closed 1 week ago

crystalfp commented 1 year ago

Describe the feature

There is a shorthand listen(...args) (line 86 in application.js) for http.createServer(app.callback()).listen(...) but no shorthand for:

http2.createSecureServer(options, app.callback()).listen(...)

Could it be added? This way will be solved also a recent typing problem created by callback() return type. Thanks!

Checklist

iwanofski commented 1 year ago

FYI You could quite easily add this yourself as well by extending Koa.

class MyKoa extends Koa {
  listenSecure(...args) {
    return http2.createSecureServer(...)
  }
}
crystalfp commented 1 year ago

Nice! But adding this myself does not decreases the code lines in my code. For this I proposed it as a new feature.

siakc commented 8 months ago

Describe the feature

There is a shorthand listen(...args) (line 86 in application.js) for http.createServer(app.callback()).listen(...) but no shorthand for:

http2.createSecureServer(options, app.callback()).listen(...)

Could it be added? This way will be solved also a recent typing problem created by callback() return type. Thanks!

It is not possible as the http2 is not imported into Koa and I guess http2 is not officially supported.

kravorkid commented 2 months ago

Submitted a PR for this here https://github.com/koajs/koa/pull/1833