Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connecting to Heroku #23

Open
tyronen opened this issue Oct 6, 2020 · 1 comment
Open

Connecting to Heroku #23

tyronen opened this issue Oct 6, 2020 · 1 comment

Comments

@tyronen
Copy link

tyronen commented Oct 6, 2020

Summary

I'd like to connect to a Postgres instance running in Heroku.

Additional context

I use Heroku's DATABASE_URL environment variable, with the suffix ?ssl=1 in my connectionString. When I run gatsby develop I get this error:

[client] success onPreBootstrap - 0.015s
[client] success createSchemaCustomization - 0.006s
[client]
[client]  ERROR #11321  PLUGIN
[client]
[client] "gatsby-source-pg" threw an error while running the sourceNodes lifecycle:
[client]
[client] self signed certificate
[client]
[client]
[client]
[client]   Error: self signed certificate
[client]
[client]   - From previous event:
[client]
[client]   - api-runner-node.js:460 Promise.catch.decorateEvent.pluginName
[client]     [yl]/[gatsby]/src/utils/api-runner-node.js:460:9
[client]
[client]   - From previous event:
[client]
[client]   - api-runner-node.js:459
[client]     [yl]/[gatsby]/src/utils/api-runner-node.js:459:14
[client]
[client]   - timers.js:456 processImmediate
[client]     internal/timers.js:456:21
[client]
[client]   - From previous event:
[client]
[client]   - api-runner-node.js:451
[client]     [yl]/[gatsby]/src/utils/api-runner-node.js:451:13
[client]
[client]   - From previous event:
[client]
[client]   - api-runner-node.js:367 module.exports
[client]     [yl]/[gatsby]/src/utils/api-runner-node.js:367:3
[client]
[client]   - source-nodes.ts:97 _default
[client]     [yl]/[gatsby]/src/utils/source-nodes.ts:97:9
[client]
[client]   - source-nodes.ts:24 sourceNodes
[client]     [yl]/[gatsby]/src/services/source-nodes.ts:24:9
[client]
[client]   - interpreter.js:707 Interpreter.exec
[client]     [yl]/[xstate]/lib/interpreter.js:707:27
[client]
[client]   - interpreter.js:210 Interpreter.execute
[client]     [yl]/[xstate]/lib/interpreter.js:210:22
[client]
[client]   - interpreter.js:230 Interpreter.update
[client]     [yl]/[xstate]/lib/interpreter.js:230:18
[client]
[client]   - interpreter.js:131
[client]     [yl]/[xstate]/lib/interpreter.js:131:23
[client]
[client]   - scheduler.js:60 Scheduler.process
[client]     [yl]/[xstate]/lib/scheduler.js:60:13
[client]
[client]   - scheduler.js:44 Scheduler.schedule
[client]     [yl]/[xstate]/lib/scheduler.js:44:14
[client]
[client]   - interpreter.js:127 Interpreter.send
[client]     [yl]/[xstate]/lib/interpreter.js:127:29
[client]
[client]   - interpreter.js:825 actor.id
[client]     [yl]/[xstate]/lib/interpreter.js:825:23
[client]
[client]
[client] warn The gatsby-source-pg plugin has generated no Gatsby nodes. Do you need it?
@benjie
Copy link
Member

benjie commented Oct 6, 2020

For more information on this error, see: brianc/node-postgres#2009

Indicating the right SSL certificate using the ?sslrootcert=... option should work, but it's kind of finicky to get it to work. I had success on Node 12 doing this, but on Node 14 not so much.

Since we're using a connection string, we can't just add rejectUnauthorized: false (though you could try it with ?rejectUnauthorized=0 or similar, I suppose).

I recently raised this PR against pg-connection-string to allow for parsing ?sslmode=no-verify, but I'm not sure if it's released yet: brianc/node-postgres#2345

Another option is to disable Node's TLS validation; e.g.:

process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;

https://stackoverflow.com/a/21961005/141284

Ultimately this is an issue between the pg module, your Node version, your server's trusted SSL certificates, and your database server. gatsby-source-pg has very little say in the matter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants