-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Adding routes dynamically #124
Comments
Hi @infiniteshroom, Yes, it is possible. Nest uses behind scenes ExpressJS as HTTP module. This allows you call the factory method with an explicit express instance and use it as you want. I don't think this an idiomatic way to do it with Nest, but it will work. ....
const expressInstance = express();
expressInstance.use(morgan('dev'));
const app = NestFactory.create(ApplicationModule, expressInstance);
expressInstance.get('/foo', function (req, res) {
res.send('bar');
})
... |
Thanks @cristianmartinez. This looks to be what I'm after, much appreciated. Do you know if this will also allow me to call nest controller methods? |
@infiniteshroom I think you can do it, but you will lose all the power of the Nest Controller. Nest uses internally a container which resolves all dependencies meta-data assigned by the decorators. If you want to call the controller directly there is no interpretation of that. I was trying to get the container but this is a private instance of the application. On Laravel, you can have the container instance on each Provider (Think as a Provider as a standard way to connect your custom code with the framework), it allows to dynamically register and gets instances of the container and for me, this approach is very flexible and powerful. I hope one day something like that comes to this awesome framework @kamilmysliwiec :) |
Hi @infiniteshroom, |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi guys. Just discovered this framework today and it's awesome, really like that it allows me to follow the same structure and setup as angular on the back end. Can't wait to get into the meat of doing something with it.
Got a question though regarding routing. From what I can see from the docs, the only way to add routes is by using a decorator on the controller. I was wondering if at all its possible to define routes dynamically.
For instance in laravel we can do something like this:
Route::get($uri, $callback);
Cheers,
Mark.
The text was updated successfully, but these errors were encountered: