Skip to content
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

Unable to use nestjs and admin-bro in the same app due to body-parser and formidable. #5

Open
blombergniklas opened this issue Oct 28, 2020 · 5 comments
Labels
bug Something isn't working

Comments

@blombergniklas
Copy link

Backend api built with nestjs serves call at /, endpoints looks like /users/me or /auth/login etc.
Before adding AdminBro, call to /auth/login with post body of {"email": "<some-email>", "password": "<some-password>" } works fine.
But when adding a module named Backoffice to my app.module.ts post body is not found when calling /auth/login and throws an exception in the controller.
All calls to AdminBro works fine under /admin

@Module({
    imports: [
      AdminModule.createAdminAsync({
        imports: [
          TypeOrmModule.forRootAsync({
            imports: [SharedModule],
            inject: [ConfigService],
            useFactory: (configService: ConfigService) => configService.typeOrmConfig,
          }),
          UsersModule,
        ],
        inject: [UsersService, ConfigService],
        useFactory: (usersService: UsersService, configService: ConfigService) => {
          return {
            adminBroOptions: {
              rootPath: '/admin',
              resources: AdminBroResources,
            },
            auth: {
              authenticate: async (email, password) => {
                const user = await usersService.findOne({
                  email: email,
                  password: ConfigService.getPasswordsHash(password),
                });
                if (user) {
                  return { email: `${user.firstName}`, title: user.email.split('@')[0] };
                }
                return false;
              },
              cookiePassword: configService.get('COOKIE_SECRET'),
              cookieName: 'backoffice',
            },
          } as AdminModuleOptions;
        },
      }),
    ],
    // providers: [UsersService],
  })
  export class BackofficeModule {}

package.json dependencies used:

"@admin-bro/express": "^3.0.1", 
"@admin-bro/nestjs": "^1.0.0", 
"@admin-bro/typeorm": "^1.3.0", 
"express-formidable": "^1.2.0",

I've narrowed it down to ExpressLoader in this repo which moves jsonParser and urlencodeparser in layer stack below AdminBro router. Commenting this out breaks AdminBro but nestjs api works again.

@SimonB407 SimonB407 added the bug Something isn't working label Nov 26, 2020
@hra4h03
Copy link

hra4h03 commented Jan 7, 2021

Same here. How about adding admin panel as microservice?

@maxpeterson
Copy link

Is this related to #7? I was able to overcome similar auth issues by using the approach outlined in #7 (comment)

@blombergniklas
Copy link
Author

@maxpeterson its working for me also with your setup. Thanks!

@Saidmurodjon
Copy link

you must add app.use(express.json()); to index.js

@Panchami-Hebbar
Copy link

node:internal/modules/esm/resolve:257
admin-dashboard | throw new ERR_MODULE_NOT_FOUND(
admin-dashboard | ^
admin-dashboard |
admin-dashboard | Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/dist/app.module' imported from /app/dist/main.js
admin-dashboard | at finalizeResolution (node:internal/modules/esm/resolve:257:11)
admin-dashboard | at moduleResolve (node:internal/modules/esm/resolve:914:10)
admin-dashboard | at defaultResolve (node:internal/modules/esm/resolve:1038:11)
admin-dashboard | at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
admin-dashboard | at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
admin-dashboard | at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
admin-dashboard | at ModuleJob._link (node:internal/modules/esm/module_job:126:49) {
admin-dashboard | code: 'ERR_MODULE_NOT_FOUND',
admin-dashboard | url: 'file:///app/dist/app.module'
admin-dashboard | }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants