Skip to content

Commit 92bdc6d

Browse files
authored
Merge branch 'nestjs:master' into fix-fastify-platfom-custom-methods
2 parents 2c2f385 + 4c66f27 commit 92bdc6d

File tree

115 files changed

+2047
-1992
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+2047
-1992
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
packages/*/package-lock.json
2-
sample/*/package-lock.json
2+
sample/**/package-lock.json
33

44
# dependencies
55
node_modules/

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Stack Overflow is a much better place to ask questions since:
2525

2626
<!-- - there are thousands of people willing to help on Stack Overflow [maybe one day] -->
2727

28-
- questions and answers stay available for public viewing so your question / answer might help someone else
28+
- questions and answers stay available for public viewing so your question / answer might help someone else.
2929
- Stack Overflow's voting system assures that the best answers are prominently visible.
3030

3131
To save your and our time, we will systematically close all issues that are requests for general support and redirect people to Stack Overflow.

integration/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ services:
5151
zookeeper:
5252
container_name: test-zookeeper
5353
hostname: zookeeper
54-
image: confluentinc/cp-zookeeper:7.8.0
54+
image: confluentinc/cp-zookeeper:7.9.0
5555
ports:
5656
- "2181:2181"
5757
environment:
@@ -60,7 +60,7 @@ services:
6060
kafka:
6161
container_name: test-kafka
6262
hostname: kafka
63-
image: confluentinc/cp-kafka:7.8.0
63+
image: confluentinc/cp-kafka:7.9.0
6464
depends_on:
6565
- zookeeper
6666
ports:

integration/hello-world/e2e/middleware-execute-order.spec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,17 @@ class GlobalModule {
2222
}
2323
}
2424

25-
@Module({ imports: [GlobalModule] })
25+
@Global()
26+
@Module({})
27+
class GlobalModule2 {
28+
configure(consumer: MiddlewareConsumer) {
29+
consumer
30+
.apply((req, res, next) => res.send(RETURN_VALUE_GLOBAL + '2'))
31+
.forRoutes('ping');
32+
}
33+
}
34+
35+
@Module({ imports: [GlobalModule, GlobalModule2] })
2636
class ModuleX {
2737
configure(consumer: MiddlewareConsumer) {
2838
consumer

integration/hello-world/e2e/middleware-fastify.spec.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,14 @@ describe('Middleware (FastifyAdapter)', () => {
450450
.apply((req, res, next) => {
451451
req.extras = { data: 'Data attached in middleware' };
452452
req.headers['ping'] = 'pong';
453+
454+
// When global prefix is set and the route is the root path
455+
if (req.originalUrl === '/api') {
456+
return res.end(JSON.stringify({ success: true, pong: 'pong' }));
457+
}
453458
next();
454459
})
455-
.forRoutes('*');
460+
.forRoutes('{*path}');
456461
}
457462
}
458463

@@ -464,7 +469,7 @@ describe('Middleware (FastifyAdapter)', () => {
464469
).createNestApplication<NestFastifyApplication>(new FastifyAdapter());
465470
});
466471

467-
it(`GET forRoutes('*') with global prefix`, async () => {
472+
it(`GET forRoutes('{*path}') with global prefix (route: /api/pong)`, async () => {
468473
app.setGlobalPrefix('/api');
469474
await app.init();
470475
await app.getHttpAdapter().getInstance().ready();
@@ -483,7 +488,26 @@ describe('Middleware (FastifyAdapter)', () => {
483488
);
484489
});
485490

486-
it(`GET forRoutes('*') without prefix config`, async () => {
491+
it(`GET forRoutes('{*path}') with global prefix (route: /api)`, async () => {
492+
app.setGlobalPrefix('/api');
493+
await app.init();
494+
await app.getHttpAdapter().getInstance().ready();
495+
return app
496+
.inject({
497+
method: 'GET',
498+
url: '/api',
499+
})
500+
.then(({ payload }) =>
501+
expect(payload).to.be.eql(
502+
JSON.stringify({
503+
success: true,
504+
pong: 'pong',
505+
}),
506+
),
507+
);
508+
});
509+
510+
it(`GET forRoutes('{*path}') without prefix config`, async () => {
487511
await app.init();
488512
await app.getHttpAdapter().getInstance().ready();
489513
return app
@@ -501,7 +525,7 @@ describe('Middleware (FastifyAdapter)', () => {
501525
);
502526
});
503527

504-
it(`GET forRoutes('*') with global prefix and exclude patterns`, async () => {
528+
it(`GET forRoutes('{*path}') with global prefix and exclude patterns`, async () => {
505529
app.setGlobalPrefix('/api', { exclude: ['/'] });
506530
await app.init();
507531
await app.getHttpAdapter().getInstance().ready();
@@ -511,7 +535,7 @@ describe('Middleware (FastifyAdapter)', () => {
511535
.expect(200, { success: true, root: true });
512536
});
513537

514-
it(`GET forRoutes('*') with global prefix and global prefix options`, async () => {
538+
it(`GET forRoutes('{*path}') with global prefix and global prefix options`, async () => {
515539
app.setGlobalPrefix('/api', { exclude: ['/'] });
516540
await app.init();
517541
await app.getHttpAdapter().getInstance().ready();
@@ -528,7 +552,7 @@ describe('Middleware (FastifyAdapter)', () => {
528552
.expect(200, { success: true, root: true });
529553
});
530554

531-
it(`GET forRoutes('*') with global prefix that not starts with /`, async () => {
555+
it(`GET forRoutes('{*path}') with global prefix that not starts with /`, async () => {
532556
app.setGlobalPrefix('api');
533557
await app.init();
534558
await app.getHttpAdapter().getInstance().ready();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { INestApplication } from '@nestjs/common';
2+
import { Test } from '@nestjs/testing';
3+
import { expect } from 'chai';
4+
import * as request from 'supertest';
5+
import { LazyController } from '../src/lazy.controller';
6+
7+
describe('Lazy Requested Scoped providers', () => {
8+
let app: INestApplication;
9+
10+
beforeEach(async () => {
11+
const module = await Test.createTestingModule({
12+
controllers: [LazyController],
13+
}).compile();
14+
15+
app = module.createNestApplication();
16+
await app.init();
17+
});
18+
19+
it('should not recreate dependencies for default scope', async () => {
20+
const resultOne = await request(app.getHttpServer()).get('/lazy/request');
21+
22+
expect(resultOne.text).to.be.equal('Hi! Counter is 1');
23+
expect(resultOne.statusCode).to.be.equal(200);
24+
25+
const resultTwo = await request(app.getHttpServer()).get('/lazy/request');
26+
27+
expect(resultTwo.text).to.be.equal('Hi! Counter is 2');
28+
expect(resultTwo.statusCode).to.be.equal(200);
29+
});
30+
});

integration/lazy-modules/src/lazy.controller.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ export class LazyController {
1313
const { TransientService } = await import('./transient.service');
1414
const _service = await moduleRef.resolve(TransientService);
1515

16+
return _service.eager();
17+
}
18+
@Get('request')
19+
async execRequestScope() {
20+
const { RequestLazyModule } = await import('./request.module');
21+
const moduleRef = await this.lazyLoadModule.load(() => RequestLazyModule);
22+
23+
const { RequestService } = await import('./request.service');
24+
const _service = await moduleRef.resolve(RequestService);
25+
1626
return _service.eager();
1727
}
1828
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Module } from '@nestjs/common';
2+
import { EagerService } from './eager.module';
3+
import { GlobalService } from './global.module';
4+
import { RequestService } from './request.service';
5+
6+
@Module({
7+
imports: [],
8+
providers: [RequestService, GlobalService, EagerService],
9+
exports: [RequestService],
10+
})
11+
export class RequestLazyModule {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Injectable, Scope } from '@nestjs/common';
2+
import { EagerService } from './eager.module';
3+
4+
@Injectable({ scope: Scope.REQUEST })
5+
export class RequestService {
6+
constructor(private eagerService: EagerService) {}
7+
8+
eager() {
9+
return this.eagerService.sayHello();
10+
}
11+
}

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"packages": [
44
"packages/*"
55
],
6-
"version": "11.0.5"
6+
"version": "11.0.12"
77
}

0 commit comments

Comments
 (0)