I am creating a NodeJS boilerplate, as it was a framework, and I want to "register" the routes or endpoints when the application starts. I want to have an array of route classes and then instantiate them. Similar to what NestJs does with their Controllers
. Then I want to loop through the collection and create instances of each Route
passed in the array. Something as the following:
class RegisterRoutes() {
routes: [FirstRoute, SecondRoute];
instatiateRoutes() {
for (route in routes) {
new route()
}
}
}
Is this a good practice?
Aucun commentaire:
Enregistrer un commentaire