Skip to content

Help: Recommended way to load routes dynamically from other files #559

@panigrah

Description

@panigrah

is the below an acceptable way to load child routes dynamically?

for (const file of expandGlobSync('**/protected/*.routes.ts')) {
  const basename = file.name.split('.')[0]
  logger.info('Setting up protected routes for', basename)
  const childRouter = (await import('./protected/' + file.name)).default
  router.use(`/${basename}`, authorized, childRouter.routes(), childRouter.allowedMethods())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions