Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
  • Loading branch information
freben committed Nov 11, 2021
1 parent a8732a1 commit 6f27670
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
18 changes: 7 additions & 11 deletions packages/backend-common/src/service/lib/ServiceBuilderImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,28 +174,24 @@ export class ServiceBuilderImpl implements ServiceBuilder {
const server: http.Server = httpsSettings
? await createHttpsServer(app, httpsSettings, logger)
: createHttpServer(app, logger);
const stoppableServer = stoppable(server, 0);

useHotCleanup(this.module, () =>
stoppableServer.stop((e: any) => {
if (e) console.error(e);
}),
);

return new Promise((resolve, reject) => {
function handleStartupError(e: unknown) {
server.close();
reject(e);
}

app.on('error', handleStartupError);
server.on('error', handleStartupError);

server.listen(port, host, () => {
app.off('error', handleStartupError);
server.off('error', handleStartupError);

const stoppableServer = stoppable(server, 0);

useHotCleanup(this.module, () =>
stoppableServer.stop((e: any) => {
if (e) console.error(e);
}),
);

logger.info(`Listening on ${host}:${port}`);
resolve(stoppableServer);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ async function main() {

await service.start().catch(err => {
logger.error(err);
throw err;
process.exit(1);
});
}

Expand Down

0 comments on commit 6f27670

Please sign in to comment.