Skip to content

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

Merged
kamilmysliwiec merged 1 commit into
nestjs:8.0.0from
branbranmuffin:feature/listen-exception-handler
Jan 27, 2021
Merged

kamilmysliwiec merged 1 commit into
nestjs:8.0.0from
branbranmuffin:feature/listen-exception-handler

Conversation

@branbranmuffin

@branbranmuffin branbranmuffin commented Nov 8, 2019 •

Copy link
Copy Markdown
Contributor

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

coveralls commented Nov 8, 2019 •

Copy link
Copy Markdown

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

Comment thread packages/core/nest-application.ts Outdated
if (address) {
this.httpServer.removeListener('error', errorHandler);
this.isListening = true;
this.logger.log(`Server listening at ${this.formatAddress(address)}`);

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread packages/core/nest-application.ts Outdated
});
}

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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