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

feat(core): change listen to reject on server bind failures #3360

Merged

Conversation

branbranmuffin
Copy link
Contributor

@branbranmuffin branbranmuffin commented Nov 8, 2019

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?
Updates the app listen function to return a promise. Allows developer to see http bind errors and handle them when calling app.listen(). Also logs url on successful server startup.

[ ] Bugfix
[X] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

The app would exit silently if the server failed to bind.
Issue 3209

Issue Number: 3209

What is the new behavior?

Updates the app listen function to return a promise. Allows developer to see http bind errors and handle them when calling app.listen(). Also logs url on successful server startup.

Does this PR introduce a breaking change?

[x] Yes
[] No

Other information

@coveralls
Copy link

coveralls commented Nov 8, 2019

Pull Request Test Coverage Report for Build f53a9d1a-cad8-4ba0-b94c-921bd5f9b973

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 94.741%

Totals Coverage Status
Change from base Build 88e83ba5-9d12-4081-8a7c-2b1c08a9989b: 0.0%
Covered Lines: 5080
Relevant Lines: 5362

💛 - Coveralls

if (address) {
this.httpServer.removeListener('error', errorHandler);
this.isListening = true;
this.logger.log(`Server listening at ${this.formatAddress(address)}`);
Copy link
Member

Choose a reason for hiding this comment

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

We decided to don't log anything automatically leaving this decision to the developer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the automatic log here.

resolve(this.httpServer);
}
});
});
}

public listenAsync(port: number | string, hostname?: string): Promise<any> {
Copy link
Member

Choose a reason for hiding this comment

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

This method can be depracated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed listenAsync function.

callback?: () => void,
): Promise<any>;
public async listen(port: number | string): Promise<any>;
public async listen(port: number | string, hostname: string): Promise<any>;
Copy link
Member

Choose a reason for hiding this comment

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

Remember to update INestApplication as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated👍

import { AppModule } from '../src/app.module';
import { INestApplication } from '@nestjs/common';

describe('Listen (Express Application', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Fastify here instead of Express, and add missing closing parentheses

import { AppModule } from '../src/app.module';
import { INestApplication } from '@nestjs/common';

describe('Listen (Express Application', () => {
Copy link
Member

Choose a reason for hiding this comment

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

add missing closing parentheses

@branbranmuffin branbranmuffin force-pushed the feature/listen-exception-handler branch 2 times, most recently from ec75e10 to b986129 Compare January 13, 2021 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants