NestJS - How to add a dynamic routing to the controller?

Viewed 2177

I have the following problem. Let's say I have an array of routes & paths to static resources, e.g.

const routes = [{ url: '/', path: 'assets/www' }]

What I would like to do is to create a set of dynamic routes to serve static resources. In express application I would do smth like:

const router = express.Router();    
routes.forEach(route => {
   router.use(route.url, express.static(path.join(__dirname, route.path)))
})

But is it possible to create such a logic inside a NestJS controller?

@Controller()
export class ItemsController {
  constructor() {}

  @Get()
  findAll() {}

  @Get(':id')
  findOne() {}

  ....
}

As far as I can see all HTTP request handlers should be predefined using the corresponding decorators.

0 Answers
Related