Skip to content

Commit

Permalink
feature(@nestjs/core) update INestApplication listen() method
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Oct 1, 2017
1 parent 7589a8a commit 23b46eb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const databaseProviders = [
password: 'root',
database: 'test',
entities: [
__dirname + '/../**/**.entity.ts',
__dirname + '/../**/**.entity{.ts,.js}',
],
autoSchemaSync: true,
}),
Expand Down
5 changes: 4 additions & 1 deletion src/common/interfaces/nest-application.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,21 @@ export interface INestApplication {
* Starts the application.
*
* @param {number} port
* @param {string} hostname
* @param {Function} callback Optional callback
* @returns Promise
*/
listen(port: number, callback?: () => void): Promise<any>;
listen(port: number, hostname: string, callback?: () => void): Promise<any>;

/**
* Starts the application and can be awaited.
*
* @param {number} port
* @param {string} hostname (optional)
* @returns Promise
*/
listenAsync(port: number): Promise<any>;
listenAsync(port: number, hostname?: string): Promise<any>;

/**
* Setups the prefix for the every HTTP route path
Expand Down
10 changes: 6 additions & 4 deletions src/core/nest-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,18 @@ export class NestApplication implements INestApplication {
this.express.use(requestHandler);
}

public async listen(port: number, callback?: () => void) {
public async listen(port: number, callback?: () => void);
public async listen(port: number, hostname: string, callback?: () => void);
public async listen(port: number, ...args) {
(!this.isInitialized) && await this.init();

this.server = this.express.listen(port, callback);
this.server = this.express.listen(port, ...args);
return this.server;
}

public listenAsync(port: number): Promise<any> {
public listenAsync(port: number, hostname?: string): Promise<any> {
return new Promise((resolve) => {
const server = this.listen(port, () => resolve(server));
const server = this.listen(port, hostname, () => resolve(server));
});
}

Expand Down

0 comments on commit 23b46eb

Please sign in to comment.