I am trying to host an API implemented as a Node.js app on Google Cloud App Engine. The database that the API utilizes is a PostgreSQL 9.6 database which is hosted with a Cl
As per Vadim's comment, UNIX sockets must be used to connect from App Engine to Cloud SQL otherwise IP whitelisting must be involved, something which there is little guides on how to do.
To accomplish this, we simply change the host
from 35.194.32.254
to the UNIX socket /cloudsql/my-project-12345:us-central1:mydatabase
:
module.exports = require('knex')({
client: 'pg',
debug: true,
connection: {
host : '/cloudsql/esp-mobile-182605:us-central1:esp-db', // 127.0.0.1 for local testing, 35.194.32.254 to locally use hosted db on Cloud SQL
user: 'postgres',
password: 'seniordesign',
database: 'esp_db'
},
});