moleculerjs / moleculer

:rocket: Progressive microservices framework for Node.js
https://moleculer.services/
MIT License
6.13k stars 580 forks source link

Something like aws-serverless-express #359

Closed yuluyi closed 6 years ago

yuluyi commented 6 years ago

Is your feature request related to a problem? Please describe.

Use case:

I have a web app built on NestJS. Its http server is based on Express. I want to integrate this web app into moleculer. There are two solutions:

  1. Let my web app listen on some port. Expose it as an api gateway.
  2. Like aws-serverless-express, start my web app without listening to any port. Let Moleculer format a http request from ctx, then forward the request to my web app.

Describe the solution you'd like

I prefer solution 2 because it is cleaner. It allows other service to call this service directly rather than taking a detour to send the http request to the api gateway. Also, solution 2 provides possibilities that we can migrate the original web app to moleculer service structure little by little.

But I can't find a way to build http request from moleculer ctx.

Describe alternatives you've considered

Additional context

icebob commented 6 years ago

If I understand correctly, you would like a Moleculer-Nest sidecar in order to call Nest API from Moleculer services via broker.call?

yuluyi commented 6 years ago

@icebob NestJS already provides a ExecutionContext selector. You can select and call whatever service or controller inside the nest web app. If we directly wire broker.call to the service or controller, the http request is not provided, so all the middlewares and auth guards will not work.

I prefer the aws-serverless-express approach. It creates the web app but doesn't listen to any port. It rebuilds the http request from lambda event, and then sends the request directly to web app through the socket.

icebob commented 6 years ago

If you create an example repo which contains a simple moleculer project and a simple Nest web app, I will try to do something.

yuluyi commented 6 years ago

Never mind. I just found I can use traefik to proxy the request directly to nest web app. Or I can use broker.call and directly call the controller or services inside my web app if I don't care about the http context. Using both can cover all my use cases.

I'll close the issue.