Wappler, did you break environment variables?

So, the question is, Wappler, did you break environment variables? NodeJS + Wappler 4.6.3

(spoiler: YES) edit: no

db.json:

# cat app/modules/connections/db.json 
{
  "name": "db",
  "module": "dbconnector",
  "action": "connect",
  "options": {
    "client": "postgres",
    "connection": {
      "host": "{{$_ENV[DB_HOST]}}",
      "port": "{{$_ENV[DB_PORT]}}",
      "user": "{{$_ENV[DB_USER]}}",
      "password": "{{$_ENV[DB_PASS]}}",
      "database": "{{$_ENV[DB_NAME]}}"
    }
  }
}

Startup command:

PORT=81 DB_HOST=8.8.8.8 node index.js

SQL query:

  server-connect:server Got error? Error: connect ECONNREFUSED 127.0.0.1:5432
  server-connect:server     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
  server-connect:server   errno: -111,
  server-connect:server   code: 'ECONNREFUSED',
  server-connect:server   syscall: 'connect',
  server-connect:server   address: '127.0.0.1',
  server-connect:server   port: 5432
  server-connect:server } +3s

Why the hell is this connecting to 127.0.0.1? You clearly see I defined DB_HOST to 8.8.8.8, please tell me I’m not crazy, you broke this, right?

Yep, you broke this :frowning:

127.0.0.1 is the default value when no value is set.

Your expression for the environment variable is wrong and will return undefined. Change it to $_ENV["DB_HOST"] or $_ENV.DB_HOST.

Thank you! I believe this will solve the problem. Consider throwing a warning if credentials are undefined

I’ve spent quite a few hours trying to troubleshoot this, really, like an entire day :frowning: Was pretty sure this was a bug, sorry!

Environment Variables are now available in Wappler 4.9.0 UI:

This topic was automatically closed after 2 days. New replies are no longer allowed.