#Dynamically create controllers

1 messages · Page 1 of 1 (latest)

flat delta
#

Hello, everyone.

To keep it short,

  • I have three modules: AppModule (bootstrapped) , SharedModule, CustomModule

  • SharedModule contains an injectable service called StoreService and a model called modelSchemas in which mongoose schemas are assigned via a BehaviorSubject.

  • In AppModule>onModuleInit, storeService.modelSchemas is assigned (via next function) an object of schemas (key modelName, value schema).

  • In CustomController>onModuleInit, storeService.modelSchemas is retrieved.

At this point, I want to generate controllers based on the modelSchemas (path will include embedded array names).

How can this be done, please?

Note that mongoose connections are done via a middleware as uri is indirectly defined in the Authorization token. So the method defined in the docs to make the mongoose connection has not been followed.

dapper chasm
#

I don't think you can generate NestJS controllers after the application bootstraps. The only way that comes into my mind is creating Fastify routes and binding them to the Fastify server retireved via HttpServerAdapter

white breach
# flat delta Hello, everyone. To keep it short, - I have three modules: AppModule (bootstrap...

there is one way a verry cursed (please dont bring this upon the world) way
once you (cursed these forsaken lands) will not be able to go back
and all you end up is with empty end points at best (or for worse) with no way to modify them other then stopping the server
you might as well do it manually then

but you could (should't) use node's child_process.exec() to trigger the nest cli to create a controller for you

willow eagle
white breach
willow eagle
#

Then how is it a solution to the question if its pointless? AFAIK it will only generate the files, not configure it unless you are willing to rebuild each time.

white breach
flat delta
topaz musk
flat delta