Skip to content
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

Fix server start handling (callback -> promise) #684

Merged
merged 2 commits into from Jun 3, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/index.js
Expand Up @@ -1070,17 +1070,21 @@ class Offline {
}

// All done, we can listen to incomming requests
_listen() {
return new Promise((resolve, reject) => {
this.server.start(err => {
if (err) return reject(err);
async _listen() {
try {
await this.server.start();
}
catch (e) {
// TODO FIXME
// should we just write the error to console and exit?
console.error('Unexpected error in serverless-offline.', e);
process.exit(1);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Unexpected error while starting serverless-offline server:' would be more verbose.
Otherwise I think logging the error and exiting 1 is correct.
Please remove the comments

}

this.printBlankLine();
this.serverlessLog(`Offline listening on http${this.options.httpsProtocol ? 's' : ''}://${this.options.host}:${this.options.port}`);
this.printBlankLine();
this.serverlessLog(`Offline listening on http${this.options.httpsProtocol ? 's' : ''}://${this.options.host}:${this.options.port}`);

resolve(this.server);
});
});
return this.server;
}

end() {
Expand Down