feat: exist on server start throw error (#374)

This commit is contained in:
ChengLei Shao 2022-05-13 11:20:30 +08:00 committed by GitHub
parent 2d38399766
commit 9e3995ab4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -188,14 +188,23 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
if (options?.listen?.port) {
const listen = () =>
new Promise((resolve) => {
new Promise((resolve, reject) => {
const Server = this.listen(options?.listen, () => {
resolve(Server);
});
Server.on('error', (err) => {
reject(err);
});
});
try {
//@ts-ignore
this.listenServer = await listen();
} catch (e) {
console.error(e);
process.exit(1);
}
}
await this.emitAsync('afterStart', this, options);