1

I'm having issues connecting my node-express-typeorm server with CloudSQL Postgres instance using CloudRun.

I have successfully added the database proxy based on the official doc: https://cloud.google.com/run/docs/configuring/connect-cloudsql

And set environment variable for the express services as

TYPEORM_URL=/cloudsql/[CONNECTION NAME]

But the app is failing to start as its unable to connect to the database.

slovakyan
  • 41
  • 5

1 Answers1

3

I have solved the issue. The culprit was TypeORM. TypeORM is parsing database host from TYPEORM_URL using / delimiter. And it was only reading cloudsql instead of /cloudsql/[CONNECTION NAME]. So the app was unable to connect to the correct endpoint.

To fix the issue set the following environment variables instead of TYPEORM_URL

TYPEORM_HOST=/cloudsql/[CONNECTION NAME]

TYPEORM_USERNAME=<username>

TYPEORM_PASSWORD=<password>

TYPEORM_DATABASE=<db>
slovakyan
  • 41
  • 5
  • Hi @slovakyan, good work finding the solution! Can you [accept your own answer](https://stackoverflow.blog/2009/01/06/accept-your-own-answers/)? It will make it more visible and help someone with the same issue as you find the solution. Thanks! – llompalles May 13 '19 at 07:29
  • @llompalles Hi, I'm sorry, I forgot doing that. Accepted :) – slovakyan May 14 '19 at 16:45