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.
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?
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
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.
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