-
-
Notifications
You must be signed in to change notification settings - Fork 33
fix: resolve issue with ordering of middleware being applied #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
B4nan
merged 17 commits into
mikro-orm:master
from
tsangste:multiple-database-middleware-order
Jan 23, 2025
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
dd5b999
fix: rename `mikro-orm-middleware` to `multiple-mikro-orm` and allow …
tsangste 046af6d
revert multiple-mikro-orm-module-option symbol
tsangste ff2b056
add additional test for middleware changes
tsangste 5661304
undo export changes
tsangste 58dfb65
PR fixes
tsangste 6078d0d
rename from `multiple` to `multi`
tsangste 7b70c3d
comment name correction
tsangste 6fee872
Update README.md
tsangste 6994fd1
fix: update README.md
tsangste 8512e2b
fix: PR fixes and implement fix for middleware issue on `forRoot` and…
tsangste 0206c70
add test
tsangste 06c4b8b
fixes
tsangste 13eec19
set NestModule to type
tsangste 9d7bec6
missing `type` in imports
tsangste 26cf085
update README.md
tsangste 49aa65d
Merge branch 'master' into multiple-database-middleware-order
B4nan 255be74
update packages and set peerDependency to 11.0.5 where the nestjs fix…
tsangste File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { EntityManager, MikroORM, type Options } from '@mikro-orm/core'; | ||
import { SqliteDriver } from '@mikro-orm/sqlite'; | ||
import { | ||
Controller, | ||
Get, | ||
Module, | ||
type INestApplication, | ||
Injectable, | ||
type MiddlewareConsumer, | ||
type NestMiddleware, | ||
type NestModule, | ||
} from '@nestjs/common'; | ||
import { Test, type TestingModule } from '@nestjs/testing'; | ||
import request from 'supertest'; | ||
import { MikroOrmModule } from '../src'; | ||
import { Foo } from './entities/foo.entity'; | ||
|
||
const testOptions: Options = { | ||
dbName: ':memory:', | ||
driver: SqliteDriver, | ||
baseDir: __dirname, | ||
entities: ['entities'], | ||
}; | ||
|
||
@Controller('/foo') | ||
class FooController { | ||
|
||
constructor(private database1: MikroORM) {} | ||
|
||
@Get() | ||
foo() { | ||
return this.database1.em !== this.database1.em.getContext(); | ||
} | ||
|
||
} | ||
|
||
@Injectable() | ||
export class TestMiddleware implements NestMiddleware { | ||
|
||
constructor(private readonly em: EntityManager) {} | ||
|
||
use(req: unknown, res: unknown, next: (...args: any[]) => void) { | ||
this.em.setFilterParams('id', { id: '1' }); | ||
|
||
return next(); | ||
} | ||
|
||
} | ||
|
||
@Module({ | ||
imports: [MikroOrmModule.forFeature([Foo])], | ||
controllers: [FooController], | ||
}) | ||
class FooModule implements NestModule { | ||
|
||
configure(consumer: MiddlewareConsumer): void { | ||
consumer | ||
.apply(TestMiddleware) | ||
.forRoutes('/'); | ||
} | ||
|
||
} | ||
|
||
@Module({ | ||
imports: [ | ||
MikroOrmModule.forRootAsync({ | ||
useFactory: () => testOptions, | ||
}), | ||
FooModule, | ||
], | ||
}) | ||
class TestModule {} | ||
|
||
describe('Middleware executes request context', () => { | ||
let app: INestApplication; | ||
|
||
beforeAll(async () => { | ||
const moduleFixture: TestingModule = await Test.createTestingModule({ | ||
imports: [TestModule], | ||
}).compile(); | ||
|
||
app = moduleFixture.createNestApplication(); | ||
|
||
await app.init(); | ||
}); | ||
|
||
it(`forRoutes(/foo) should return 'true'`, () => { | ||
return request(app.getHttpServer()).get('/foo').expect(200, 'true'); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.close(); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.