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

RouterModule nested import #8364

Closed
5 of 15 tasks
bellus93 opened this issue Oct 18, 2021 · 7 comments
Closed
5 of 15 tasks

RouterModule nested import #8364

bellus93 opened this issue Oct 18, 2021 · 7 comments

Comments

@bellus93
Copy link

bellus93 commented Oct 18, 2021

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

RouterModule doesn't work on submodules

@Module({
  imports: [
    AuthenticationModule,
    RolesModule,
    PermissionsModule,
    ResourcesModule,
    PasswordRecoveriesModule,
    SharedModule,
    ImagesModule,
    SubscriptionsModule,
    LoginAttemptsModule,
    ProjectsModule,
    CompaniesModule,
    UsersModule,
    SubscriptionTypesModule,
    CompanyEcommerceModule,
    CompanyEcommerceTypesModule,
    CompanyEmployeesModule,
    InvitationsModule,
    CountriesModule,
    ProjectTypesModule,
    CompanyAddressesModule,
    PromoCodesModule,
    ShopifyModule,
    SubscriptionTypeValuesModule,
    UserProjectsModule,
    ProjectStagesModule,
    SubscriptionValueUnitsModule,
    ProjectDataModule,
    ProjectGoalsPartnersModule,
    ProjectGoalPartnerAssociationsModule,
    StripeWebhookModule,
    ReportsModule,
    ProjectGalleryModule,
    SinglePaymentsModule,
    SinglePaymentPacksModule,
    SubscriptionTypeGroupsModule,
  ],
})
export class AdminModule {}

in the AppModule i have

import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { SequelizeModule } from '@nestjs/sequelize';
import { MailchimpModule } from '@mindik/mailchimp-nestjs';
import { StripeModule } from 'nestjs-stripe';
import { AdminModule } from './admin/admin.module';

@Module({
  imports: [
    ...
    AdminModule,
    RouterModule.register([
      {
        path: 'api',
        module: AdminModule
      }
    ])
  ],
  controllers: [AppController],
  providers: [AppService],
  exports: [AppService],
})
export class AppModule {}

Minimum reproduction code

https://github.com/bellus93/test

Steps to reproduce

No response

Expected behavior

Also the submodules use the prefix
I cannot use global prefix because I want use different prefixes for different modules

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

No response

Packages versions

{
"name": "green-future-project-backend-nest",
"version": "1.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write "src//*.ts" "test//.ts"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint "{src,apps,libs,test}/**/
.ts" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@mailchimp/mailchimp_marketing": "^3.0.55",
"@mailchimp/mailchimp_transactional": "^1.0.33",
"@mindik/mailchimp-nestjs": "^1.0.4",
"@nestjs/common": "^8.0.3",
"@nestjs/config": "^1.0.0",
"@nestjs/core": "^8.0.3",
"@nestjs/jwt": "^8.0.0",
"@nestjs/mapped-types": "^1.0.0",
"@nestjs/platform-express": "^8.0.3",
"@nestjs/sequelize": "^8.0.0",
"@types/dotenv": "^8.2.0",
"ajv": "^8.4.0",
"aws-sdk": "^2.1008.0",
"bcrypt": "^5.0.1",
"chart.js": "^3.5.1",
"chartjs-node-canvas": "^4.0.1",
"google-auth-library": "^7.10.1",
"mysql2": "^2.2.5",
"nestjs-stripe": "^1.0.0",
"pdfkit": "^0.12.3",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "7.2.0",
"sequelize": "6.7.0",
"sequelize-typescript": "^2.1.0",
"shopify-api-node": "^3.6.12",
"shopify-token": "^4.0.4",
"stripe": "^8.182.0",
"uuid": "^8.3.2"
},
"devDependencies": {
"@nestjs/cli": "^8.0.2",
"@nestjs/schematics": "^8.0.1",
"@nestjs/testing": "^8.0.3",
"@types/bcrypt": "^5.0.0",
"@types/express": "^4.17.11",
"@types/jest": "^27.0.2",
"@types/multer": "^1.4.5",
"@types/node": "^16.11.0",
"@types/sequelize": "^4.28.9",
"@types/supertest": "^2.0.10",
"@types/validator": "^13.1.3",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^7.20.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
"jest": "^27.2.5",
"prettier": "^2.2.1",
"supertest": "^6.1.3",
"ts-jest": "^27.0.6",
"ts-loader": "^9.1.1",
"ts-node": "^10.1.0",
"tsconfig-paths": "^3.9.0",
"typescript": "4.4.4"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".\.spec\.ts$",
"transform": {
"^.+\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/
.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}

Node.js version

16.11

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@bellus93 bellus93 added the needs triage This issue has not been looked into label Oct 18, 2021
@jmcdo29
Copy link
Member

jmcdo29 commented Oct 18, 2021

Please provide a minimum reproduction repository.

@kamilmysliwiec kamilmysliwiec added needs clarification and removed needs triage This issue has not been looked into labels Oct 19, 2021
@bellus93
Copy link
Author

@kamilmysliwiec
Copy link
Member

RouterModule should be imported only once.

@bellus93
Copy link
Author

I tried also to set only for admin module, but submodules don't get the path setted in router module

@kamilmysliwiec
Copy link
Member

As far as I can see, Admin doesn't have any controllers registered. Imported modules are not taken into account (and this is the expected behavior).

@bellus93
Copy link
Author

So, how i can set for any module that i have in the imports the prefix "admin" ? because in my main project i have more than twenty modules and I wouldn't set in all of them the prefix in the controller

@kamilmysliwiec
Copy link
Member

kamilmysliwiec commented Oct 22, 2021

@bellus93 you'd have to list all of them explicitly within the RouterModule configuration

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.

@nestjs nestjs locked and limited conversation to collaborators Oct 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants