koa icon indicating copy to clipboard operation
koa copied to clipboard

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

Open crystalfp opened this issue 1 year ago • 4 comments

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

  • [x] I have searched through GitHub issues for similar issues.
  • [x] I have completely read through the README and documentation.

crystalfp avatar Mar 29 '23 04:03 crystalfp

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

class MyKoa extends Koa {
  listenSecure(...args) {
    return http2.createSecureServer(...)
  }
}

iwanofski avatar Jun 15 '23 11:06 iwanofski

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

crystalfp avatar Jun 15 '23 12:06 crystalfp

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.

siakc avatar Dec 22 '23 10:12 siakc

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

kravorkid avatar Jun 30 '24 22:06 kravorkid