Skip to content

Commit 23b46eb

Browse files
feature(@nestjs/core) update INestApplication listen() method
1 parent 7589a8a commit 23b46eb

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

examples/05-sql-typeorm/src/modules/database/database.providers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const databaseProviders = [
1111
password: 'root',
1212
database: 'test',
1313
entities: [
14-
__dirname + '/../**/**.entity.ts',
14+
__dirname + '/../**/**.entity{.ts,.js}',
1515
],
1616
autoSchemaSync: true,
1717
}),

src/common/interfaces/nest-application.interface.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,21 @@ export interface INestApplication {
2525
* Starts the application.
2626
*
2727
* @param {number} port
28+
* @param {string} hostname
2829
* @param {Function} callback Optional callback
2930
* @returns Promise
3031
*/
3132
listen(port: number, callback?: () => void): Promise<any>;
33+
listen(port: number, hostname: string, callback?: () => void): Promise<any>;
3234

3335
/**
3436
* Starts the application and can be awaited.
3537
*
3638
* @param {number} port
39+
* @param {string} hostname (optional)
3740
* @returns Promise
3841
*/
39-
listenAsync(port: number): Promise<any>;
42+
listenAsync(port: number, hostname?: string): Promise<any>;
4043

4144
/**
4245
* Setups the prefix for the every HTTP route path

src/core/nest-application.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,18 @@ export class NestApplication implements INestApplication {
8181
this.express.use(requestHandler);
8282
}
8383

84-
public async listen(port: number, callback?: () => void) {
84+
public async listen(port: number, callback?: () => void);
85+
public async listen(port: number, hostname: string, callback?: () => void);
86+
public async listen(port: number, ...args) {
8587
(!this.isInitialized) && await this.init();
8688

87-
this.server = this.express.listen(port, callback);
89+
this.server = this.express.listen(port, ...args);
8890
return this.server;
8991
}
9092

91-
public listenAsync(port: number): Promise<any> {
93+
public listenAsync(port: number, hostname?: string): Promise<any> {
9294
return new Promise((resolve) => {
93-
const server = this.listen(port, () => resolve(server));
95+
const server = this.listen(port, hostname, () => resolve(server));
9496
});
9597
}
9698

0 commit comments

Comments
 (0)