Issue accessing CouchDB from server connect workflows - connection error

Wappler Version : 6 Beta 2
Operating System : win11
Server Model: node
Database Type: couch
Hosting Type: docker local

Expected behavior

Connection should work

Actual behavior

What actually happens?
Connection refused error

status: "500",
message: "error happened in your connection. Reason: connect ECONNREFUSED 127.0.0.1:9913",
stack: "Error: error happened in your connection. Reason: connect ECONNREFUSED 127.0.0.1:9913
    at responseHandler (/opt/node_app/node_modules/nano/lib/nano.js:157:16)
    at /opt/node_app/node_modules/nano/lib/nano.js:456:13
    at processTicksAndRejections (node:internal/process/task_queues:96:5)"
}

Sorry, more tales of woe relating to couchdb

I have a couch database running in a local docker container

image

i can connect via the admin panel on port 9913

image

I have 2 collections defined

image

and can connect via db_connection from the Database manager tab

I also have a connection defined under workflows globals

The username and password match the database settings on the Resource Manager and those used in the Database manager connection settings i.e. “myuser” + user password (displayed)

I have a simple query defined to query the notes collection using the db_connection

If i run it in a browser i get connection refused on port 9913

file: \app\modules\connections\db_connection.json

{
  "name": "db_connection",
  "module": "dbconnector",
  "action": "connect",
  "options": {
    "client": "couchdb",
    "connection": {
      "host": "127.0.0.1",
      "port": 9913,
      "user": "myuser",
      "password": "1gFD6lSfVNBXHb3t",
      "database": "my_db"
    },
    "databaseResource": "Local / couchdb",
    "cloudDatabaseName": "my_db"
  },
  "fileName": "db_connection.json"
}

.wappler\targets\Development\databases\db_connection.json

{
  "type": "couchdb",
  "connection": {
    "host": "127.0.0.1",
    "port": 9913,
    "user": "myuser",
    "password": "1gFD6lSfVNBXHb3t",
    "database": "my_db"
  },
  "direct": true,
  "databaseResource": "Local / couchdb",
  "cloudDatabaseName": "my_db",
  "schema": {
    "partitioned": false,
    "tables": {
      "notes": {
        "meta": [
          {
            "name": "_id",
            "type": "objectId"
          },
          {
            "name": "title",
            "type": "text"
          },
          {
            "name": "content",
            "type": "text"
          }
        ]
      },
      "product": {
        "meta": [
          {
            "name": "_id",
            "type": "objectId"
          },
          {
            "name": "product_id",
            "type": "number"
          },
          {
            "name": "product_name",
            "type": "text"
          }
        ]
      }
    },
    "views": {}
  }
}

db_connection.js

dmx.databases = dmx.databases || {};
dmx.databases['db_connection'] = {type: "pouchdb", remote: "http://127.0.0.1:9913/my_db"}

In frustration i decided to take radical action
I completely removed Wappler 3.8.2 and Beta 2 from my system
reinstalled both
rebuilt the site from scratch
I had hoped that may get things working so i could continue investigating couch/mysql co-existence
Sadly i have the same issue, same error message
I can access pouch/couch via app connect but accessing couch from server connect gives the same error

{
status: "500",
message: "error happened in your connection. Reason: connect ECONNREFUSED 127.0.0.1:9913",
stack: "Error: error happened in your connection. Reason: connect ECONNREFUSED 127.0.0.1:9913
    at responseHandler (/opt/node_app/node_modules/nano/lib/nano.js:157:16)
    at /opt/node_app/node_modules/nano/lib/nano.js:456:13
    at processTicksAndRejections (node:internal/process/task_queues:96:5)"
}

headers if it is anyhelp

are you running also node in docker? Then from docker perspective 127.0.0.1 is not the host machine but the local service.

So in that case host.docker.internal should be used instead of 127.0.0.1 for the server connect connections only, direct connections go fine.

I will see if we can generate that automatically when such docker connections are used in server connect

I am running web and “db” (MYSQL) in a docker container and db_connection (couch) in a separate docker container

Project Settings

Cloud DB
image

So i need to change the default URL of the database in the project’s docker container from 127.0.0.1 to “host.docker.internal”?

Where can i do this without going directly into JSON files, project settings don’t have a “host” field firvtge database or do I just change the url of the entire project?

only in the server connect database connections - will do that automatically in the next beta

1 Like

Changing to “db_connections” in globals settings from, 127.0.0.1 to “host.docker.internal” for the couch container manually did indeed fix the issue

1 Like

This has been fixed in the latest beta updates.