Skip to content

Commit 1e35db1

Browse files
authored
feat!: support Express v5 in adminjs-nestjs (#68)
* fix: await loader.register so login page will render * fix: use router instead of _router from express v5 Breaking change: From now on, adminjs-nestjs will support Express v5 only. Applications running on Express v4 (or earlier) must upgrade to Express v5 to continue using this package.
1 parent f09c6ac commit 1e35db1

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/admin.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class AdminModule implements OnModuleInit {
138138
admin.watch();
139139

140140
const { httpAdapter } = this.httpAdapterHost;
141-
this.loader.register(admin, httpAdapter, {
141+
await this.loader.register(admin, httpAdapter, {
142142
...this.adminModuleOptions,
143143
adminJsOptions: admin.options,
144144
});

src/loaders/express.loader.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,43 +58,43 @@ export class ExpressLoader extends AbstractLoader {
5858
// Nestjs uses bodyParser under the hood which is in conflict with adminjs setup.
5959
// Due to adminjs-expressjs usage of formidable we have to move body parser in layer tree after adminjs init.
6060
// Notice! This is not documented feature of express, so this may change in the future. We have to keep an eye on it.
61-
if (app && app._router && app._router.stack) {
62-
const jsonParserIndex = app._router.stack.findIndex(
61+
if (app && app.router && app.router.stack) {
62+
const jsonParserIndex = app.router.stack.findIndex(
6363
(layer: { name: string }) => layer.name === 'jsonParser',
6464
);
6565
if (jsonParserIndex >= 0) {
66-
jsonParser = app._router.stack.splice(jsonParserIndex, 1);
66+
jsonParser = app.router.stack.splice(jsonParserIndex, 1);
6767
}
6868

69-
const urlencodedParserIndex = app._router.stack.findIndex(
69+
const urlencodedParserIndex = app.router.stack.findIndex(
7070
(layer: { name: string }) => layer.name === 'urlencodedParser',
7171
);
7272
if (urlencodedParserIndex >= 0) {
73-
urlencodedParser = app._router.stack.splice(urlencodedParserIndex, 1);
73+
urlencodedParser = app.router.stack.splice(urlencodedParserIndex, 1);
7474
}
7575

76-
const adminIndex = app._router.stack.findIndex(
76+
const adminIndex = app.router.stack.findIndex(
7777
(layer: { name: string }) => layer.name === 'admin',
7878
);
7979
if (adminIndex >= 0) {
80-
admin = app._router.stack.splice(adminIndex, 1);
80+
admin = app.router.stack.splice(adminIndex, 1);
8181
}
8282

8383
// if adminjs-nestjs didn't reorder the middleware
8484
// the body parser would have come after corsMiddleware
85-
const corsIndex = app._router.stack.findIndex(
85+
const corsIndex = app.router.stack.findIndex(
8686
(layer: { name: string }) => layer.name === 'corsMiddleware',
8787
);
8888

8989
// in other case if there is no corsIndex we go after expressInit, because right after that
9090
// there are nest endpoints.
91-
const expressInitIndex = app._router.stack.findIndex(
91+
const expressInitIndex = app.router.stack.findIndex(
9292
(layer: { name: string }) => layer.name === 'expressInit',
9393
);
9494

9595
const initIndex = (corsIndex >= 0 ? corsIndex : expressInitIndex) + 1;
9696

97-
app._router.stack.splice(
97+
app.router.stack.splice(
9898
initIndex,
9999
0,
100100
...admin,

0 commit comments

Comments
 (0)