Subdomains not connecting to db - .env issues

Hi Wapplers,

My current setup is Nodejs/Docker and I setup Caddy to allow wildcard subdomains to connect to my main site. Its all working great except for the fact that my subdomains are not connecting to the database. I am getting an error: {
"status": "500",
"code": "ENOTFOUND",
"message": "getaddrinfo ENOTFOUND db",
"stack": "Error: getaddrinfo ENOTFOUND db\n at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26)"
}

So I created a .env file file inside the docker container but my app is not reading it correctly which contains my db connection details.

Anyone know why its ignoring my .env?

Huh... Ok, so, huh... You'll need to detail your setup including all relevant docker-compose files, and are you still using Wappler Docker for deployment?

Alrighty...

In the resource manager, under my remote server I right click Services and Open in Editor. That is the docker-compose.yml file that has the following:

My .env file has the following:

I reploy using Wappler --> Deploy (yes it still uses Docker to deploy)

Show me a screenshot of the DB config in Wappler so I can see it's loading from an environment variable. Don't forget to select the right target

So my primary app connects perfectly to the db and logs the user in but when I do another subdomain it directs to the correct app and loads it perfectly but it wont allow the user to login as its not connecting to the database

Seems like someone encountered the same issue: :rofl: Patrick, why .env file is ignored in production?

I'm sorry, I didn't understand :pensive:

That's true, but that's not the issue because you also have the environment variables in the docker-compose file

You have to use an expression like $_ENV.DB_HOST in that screenshot, isn't it? But I didn't understand the part where you say it works but then it doesn't (first quote)

Sorry for the confusion. app.monergise is my primary app on digital ocean that works perfectly. I then spun up a new droplet for caddy to reroute all wildcard subdomains to my primary app. This works. The part that doesnt work is that the subdomain apps will not connect to the main database that app.monergise connects to. It gives an error. The error "getaddrinfo ENOTFOUND db" means that the application is trying to connect to the database using "db" as the hostname, but Docker cannot resolve it.

The solution was to create a new .env file that contains my db details. However its not loading. It is being ignored by the server.

Thanks, I think I understand now.

I believe the quote above is the issue. Do you understand Wappler doesn't magically know what is "DB_HOST"?

Ah so you saying the setup should be something like this:

Yes, but $_ENV.DB_HOST

And you could also add a formatter .default('db') or something

I am still struggling to get this to work. I keep getting the same error on my subdomain apps: {
"status": "500",
"code": "ENOTFOUND",
"message": "getaddrinfo ENOTFOUND db",
"stack": "Error: getaddrinfo ENOTFOUND db\n at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26)"
}

Yes, Docker loads them into the container's environment so they're accessible in $_ENV. Or through a .env file but there's that bug. Make sure there's no environment variable in your project settings (in Wappler) overriding what you're defining in the docker compose file

I don't have the availability to assist further