Is there a way to add a service written in expressJs to lagom?

Hi,

I have a service which is written in expressJs and I would like to integrate that service in lagom. Basically I want my service on expressJs to run when I do a sbt> runAll.

Hi,

why do you need to run expressJs with runAll?
You can run expressJs app independently and just configure URL access to Lagom service gateway.

Hope this helps.

Br,
Alan

Fair enough.

However, why not have runAll start an unmanaged service as well? Won’t that be convenient?

Is there any way to configure runAll task to start and stop unmanaged services as well?

1 Like

@aklikic

I am not able access API end point /hello that my express service exposes at port 3000 via Service gateway running at port 9000.

I have added the following to the build.sbt so as to register my unmanaged service hello-service in the Service Registry, like so:

lagomUnmanagedServices in ThisBuild := 
      Map("hello-service" -> "http://127.0.0.1:3000")

Upon sbt reload and sbt runAll I was hoping to access http://localhost:9000/hello endpoint via curl. But it replies with the following:

Action Not Found
For request 'GET /hello'

However, I am able to access the same end point at port 3000 like so:

curl http://localhost:3000/hello
hello there 

Could you suggest, what could I be doing wrong? Thanks.

check DevEnvironment

Lagom gateway is only exposing aggregated endpoints for all Lagom services started in dev mode and not declared un-managed services. Check this.

I assume expressJs app acts as BFF (backend for frontend) and should connect to Lagom service.
You will need to connect to expressJs on port 3000 that will then connect to Lagom service via a Service Gateway on port 9000. You will need to configure, in expressJs, Lagom service endpoint via Service Gateway URL (http://localhost:9000/hello).

1 Like

Hi @aklikic , Please correct if my understand is wrong.

  1. So the purpose of the following statement from build.sbt is to register an un-managed service in Service Registry, so that other services including lagom service can interact with it.
   lagomUnmanagedServices in ThisBuild := 
        Map("hello-service" -> "http://127.0.0.1:3000")
  1. This however doesn’t mean that the requests for service hello-service will be reverse proxied by the Service Gateway. In other words, Frontend would still need to access hello-service at port 3000.

I have question here however:

What if the requirement is expose all backend services (managed/un-managed) as Platform Services exposed at single port say 9000. To my understand this should be achievable if the Service Gateway also reverse proxies the hello-service via some configuration or something, irrespective of whether services talk to each other or not. We do that all the time, right?

[managed]
http://localhost:9000/api/service1/
http://localhost:9000/api/service2/

[un-managed]
http://localhost:9000/api/hello-service/

How do we achieve the same in Lagom besides registering the service to Service Registry?

TIA.

Hi @codingkapoor,

  1. This will “configure” development service locator to map “hello-service” location to configured url
  2. correct

Service Gateway is a convenient feature, designed only for lagom DEV environment, to reverse proxy (aggregate) access to lagom services (running on different ports).
If you want to expose lagom and non-lagom services in aggregated manner then you will need to use a real reverse proxy like nginx.

Hope this helps.

Br,
Alan

1 Like

@aklikic This clarifies. Much thanks!

How about using Consul instead of nginx for this purpose? Suggestions?

Yes, but for this simple use case feels like an overhead.