Bob
Bob

Reputation: 553

How to configure sailsjs DB connection with Google Cloud SQL

I'm running a Sails.js application that uses a Google Cloud Postgresql instance on Google App Engine. I'm getting a connection refused error when I deploy the application. This is my sailsjs connection config:

postgresGoogle: {
      adapter: 'sails-postgresql',
      socketPath: '/cloudsql/' + process.env.INSTANCE_CONNECTION_NAME,
      user: 'xxxxx',
      password: 'xxxxx',
      database: 'postgres'
     }

If I add the host, it throws a timeout error. Does anyone know the proper way to configure a sailsjs connection with GCP postresql?

Upvotes: 0

Views: 296

Answers (2)

Chris Merkle
Chris Merkle

Reputation: 1

Solved

As of 16 December 2022...

I finally got Sails.js to work today with GCP SQL. If you follow the tutorials from Google you have either Unix Sockets or TCP options to try -- and sadly neither work with out of the box sails-postgres.

My workaround was to connect via a VPC connector with a dedicated IP address. This way I can connect to Cloud SQL using a regular Postgres connection string, directly to the DB.

https://cloud.google.com/appengine/docs/legacy/standard/python/outbound-ip-addresses

Then I whitelisted the new dedicated IP in Cloud SQL security settings, and forced SSL to require valid SSL certificates.

It may not be best practice for now per Google's docs, but it works.

Upvotes: 0

oakinlaja
oakinlaja

Reputation: 906

Where exactly is your Sails.js application? Is it on App Engine Flex? I would recommend deploying to App Engine Flex, as described here and then connect to the PostgreSQL from the Flex environment. Otherwise, are you using any of the option steps described in this link for connection?

Upvotes: 1

Related Questions