Cloud SQL instance connection working locally, but not on App Engine

前端 未结 1 1242
长发绾君心
长发绾君心 2021-01-13 17:44

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

1条回答
  •  隐瞒了意图╮
    2021-01-13 18:17

    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'
        },
    });
    

    0 讨论(0)
提交回复
热议问题