Some of my api endpoints use pg-promise to connect to a postgresql database.
I was using a connection string environment variable like this:
# .env
PG_CONNECTION_STRING=postgresql://cooluser:[email protected]:5432/dbname
This worked fine in production and with now dev, but once we changed the connection details, the app couldn't parse the connection string anymore. The main difference was that the new connection string had a password with special characters:
# .env
PG_CONNECTION_STRING=postgresql://cooluser:my*cool#[email protected]:5432/dbname
With now dev, I url-encoded the string in the .env file, and it worked locally. In production, with or without url-encoding the now secret, it looks like it wasn't parsing the string correctly. Is this a known issue? It could be a problem with the postgres library itself, but I was able to get it working in dev (albeit with the url encoding).
My solution/workaround was to use individual environment variables (PGHOST, PGPASSWORD, etc.) instead of a single string, and it all works fine without the need for any url encoding. So this doesn't affect my project anymore, but I'd prefer to use one string for future projects, if possible.
Thanks. We'll take a look!
Hi guys! I'm the author of pg-promise. You should switch over to proper connection-string parser, which handles connections strings better.
Symbol * can be used directly, while # has to be URL-encoded as %23. Then it will work fine.
This seems to be related to the libraries used and not the platform. Closing this and if you still think this is a platform-wide issue, please get in touch with [email protected]
Most helpful comment
Hi guys! I'm the author of
pg-promise. You should switch over to proper connection-string parser, which handles connections strings better.Symbol
*can be used directly, while#has to be URL-encoded as%23. Then it will work fine.