-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: more flexible koa server creation #88
Conversation
dd99aa2
to
b666237
Compare
- split out a generated `createRouter` function that only creates the koa router, making use of the `bootstrap` / `startServer` optional - allow passing options to the cors / koa-body middlewares, or disabling these completely - return the koa `app` and the `AddressInfo` from `startServer` / `bootstrap` - make `startServer` and `async` function that rejects if `app.listen` fails **this is a breaking change**, and probably not the last to this interface. whilst the prior iteration was far too inflexible, this doesn't feel quite right as it makes it a little too easy to construct a server that doesn't work (eg: disabling body parser without providing alternative). the bootstrap function is kinda redundant now as well, though that may not remain true so can stay for the moment. **migration:** see integration-tests/typescript-koa/src/petstore-expanded.yaml/index.ts for example
``` TS2742: The inferred type of createRouter cannot be named without a reference to koa-body/node_modules/@types/koa. This is likely not portable. A type annotation is necessary. ```
b666237
to
ea6f04e
Compare
ea6f04e
to
0826494
Compare
3c4f63a
to
5d4d992
Compare
5d4d992
to
2910981
Compare
app.use(router.allowedMethods()) | ||
app.use(router.routes()) | ||
|
||
return new Promise((resolve, reject) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty ugly use of new Promise
and several try
-catch
blocks, but whilst I don't think sever.address()
throws right now, there's a FIXME
comment suggesting it might in future, and doing this means that any exceptions will definitely stay in the promise chain correctly.
Also starts handling errors like EADDRINUSE
properly, as these get emitted as an error
event
split out a generated
createRouter
function that only createsthe koa router, making use of the
bootstrap
/startServer
functions optional
allow passing options to the
cors
/koa-body
middlewares, ordisabling these completely
support passing a
ListenOptions
instead ofport
number, allowingto bind to a specific network interface
return the koa
app
and theAddressInfo
fromstartServer
/bootstrap
make
startServer
anasync
function that rejects ifapp.listen
fails
this is a breaking change, and probably not the last to this interface.
whilst the prior iteration was far too inflexible, this doesn't feel quite right still:
startServer
still pretty inflexible/simple, and doesn't support all optionsbody: "disable"
and no suitable alternative providedbootstrap
function basically redundant now as well, though that may not remain true so can stay for the momentcloses #94