#Multiple simultaneous servers using fastify

1 messages · Page 1 of 1 (latest)

hot gorge
#

I'm trying to create an app which listens to http and https. According to the docs https://docs.nestjs.com/faq/multiple-servers, it specifies how to create such servers using express, however there is no mention how to do it correctly with fastify. I figured it could be done exactly the same way using fastify, however there is type errors when I pass fastify server to https and https create server functions.
According to this answer (tho it didn't get many upvotes but the only I could fine about that matter) https://stackoverflow.com/questions/58941575/what-is-the-correct-implementation-for-multiple-simultaneous-servers-when-runnin, he suggests creating two applications where nestjs resolves the dependencies twice, and if you set more stuff on your app, you need to duplicate everything.
I'd appreciate if anyone knows a classic way of doing it similar to express, and maybe we can add it to the docs for extra clarification.
Thanks!

hot gorge
#

I'm still looking for an answer for this issue. If anyone needs a clarification about anything feel free to ask

astral beacon
#

@hot gorge - why do you need http?

hot gorge
#

i need both http and https. https for external requests, http for internal

astral beacon
#

Ok. I think that solution noted in SO is the only way to get Fastify to run on two different ports within the same server. You are basically needing to asynchronously run two different apps in the end.

The other possibility is to have a reverse proxy in front of your app and let it do the TLS termination. I'd even venture to say, that is the better solution, because your non-TLS port will be open to the Internet too. It won't be "internal". Well, not unless your app is in a container or something, and then you'd need some form of reverse proxy anyway.

hot gorge
#

Thanks for the reply Scott!
In production we use ELB, hence we don't listen to https, all requests in cluster are http.
I just needed this option for local development.

astral beacon
#

@hot gorge - Ok. then why do you need TLS termination in your local dev environment?

hot gorge
#

We have made a trick to intercept requests from our staging dashboard (client) to a specific local service that you run on your machine. this gives us the ability to easily debug a microservice without running all its dependencies. with this solution the requests is received in https protocol to the service instead of http (because the request is no going through ELB which is also responsible to TLS termination before it hits the service in the cluster)

astral beacon
#

Of course, it's a stage/ dev environment i.e. not production directly.

hot gorge
#

I heard about telepresence but I have not read about their solution. Maybe its a staging replica of some services per developer / team? Or maybe its like we do it 🙂

#

I'll take a look at coder! never heard of it

astral beacon
#

Nah. Telepresence adds an agent sidecar (container) next to your app's container and basically intercepts its communication. On your local computer, you have a similar agent set up and receives the intercepted communication to your in-parallel-running app so you can develop with all the services running in the cloud i.e. no need to set up docker desktop or the like. It's kind of like a specialized VPN.

hot gorge
#

i'll take a look at them both, looks interesting. our solution was temporarily until we choose the right tool for us. it was actually so good that i developed it about a year ago. it has some drawbacks but it works 🙂

#

recently we started using nestjs with fastify so i needed to update our infra same as our old infra with express