mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
fix(application): makes get-url work in callback
`app.getUrl()` was throwing an error when `this.isListening` was set to false. The value was set _after_ `this.httpServer.listen` was called, now it is set _before_ to ensure that the `app.getUrl()` can be called in the callback of `listen`. A regression test has been added for this, and all tests related to the change are passing. fix: #5798
This commit is contained in:
@@ -37,6 +37,13 @@ describe('Get URL (Express Application)', () => {
|
||||
expect(await app.getUrl()).to.be.eql(`http://127.0.0.1:${port}`);
|
||||
await app.close();
|
||||
});
|
||||
it('should return 127.0.0.1 even in a callback', () => {
|
||||
const app = testModule.createNestApplication(new ExpressAdapter(express()));
|
||||
return app.listen(port, async () => {
|
||||
expect(await app.getUrl()).to.be.eql(`http://127.0.0.1:${port}`);
|
||||
await app.close();
|
||||
});
|
||||
});
|
||||
it('should throw an error for calling getUrl before listen', async () => {
|
||||
const app = testModule.createNestApplication(new ExpressAdapter(express()));
|
||||
try {
|
||||
|
||||
@@ -30,6 +30,13 @@ describe('Get URL (Fastify Application)', () => {
|
||||
expect(await app.getUrl()).to.be.eql(`http://127.0.0.1:${port}`);
|
||||
await app.close();
|
||||
});
|
||||
it('should return 127.0.0.1 even in a callback', () => {
|
||||
const app = testModule.createNestApplication(new FastifyAdapter());
|
||||
return app.listen(port, async () => {
|
||||
expect(await app.getUrl()).to.be.eql(`http://127.0.0.1:${port}`);
|
||||
await app.close();
|
||||
});
|
||||
});
|
||||
it('should throw an error for calling getUrl before listen', async () => {
|
||||
const app = testModule.createNestApplication(new FastifyAdapter());
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user