question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot access SSL certificates when deploying to production on Vercel

See original GitHub issue

Bug description

I am building a website using Nextjs + Apollo server micro + Apollo client + Prisma, with a GCP Postgresql database.

When working on my local machine, migrations, queries and mutations work on my local test database and my production database (for example running yarn prisma migrate up --experimental).

However after deployment to production, when I trigger a first query, i’m getting this error Uncaught (in promise) Error: Error opening a TLS connection: cert file not found (No such file or directory (os error 2)).

Capture d’écran 2020-11-23 à 10 52 46

For local development I use dotenv cli to manage environments for my DATABASE_URL. As SSL security is implemented the url looks like this DATABASE_URL="postgresql://USER:PASSWORD@IP:PORT/DATABASE_NAME?schema=public&sslmode=required&sslcert=../server-ca.pem&sslidentity=../client-identity.p12&sslpassword=PASSWORD&sslaccept=strict" as described in this issue

For the production build I use the Vercel Secrets feature to store the DATABASE_URL.

I have tried the solution presented here, by using the relative path to the root folder, as well as absolute path with no success.

I have tried logging the database URL on build, and it is showing me the ‘correct’ URL, (the one I implemented).

My file structure is like this . | pages |— api |—— graphql.js | prisma |— migrations |— schema.prisma | server-cert.pem | client-identity.p12

Prisma information

I’m using @prisma/client 2.11.0

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL (Google Cloud)
  • Node.js version: 14.4.0
  • Prisma version:
@prisma/cli          : 2.11.0
@prisma/client       : 2.11.0
Current platform     : darwin
Query Engine         : query-engine 58369335532e47bdcec77a2f1e7c1fb83a463918 (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine     : migration-engine-cli 58369335532e47bdcec77a2f1e7c1fb83a463918 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 58369335532e47bdcec77a2f1e7c1fb83a463918 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary        : prisma-fmt 58369335532e47bdcec77a2f1e7c1fb83a463918 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Studio               : 0.311.0

How the Prisma client is called in my graphql.js

import { makeSchema, objectType, stringArg, intArg, asNexusMethod } from '@nexus/schema'
import { GraphQLDate } from 'graphql-iso-date'
import { ApolloServer } from "apollo-server-micro";
import { PrismaClient } from '@prisma/client';
import path from 'path';

export const GQLDate = asNexusMethod(GraphQLDate, 'date')

console.log(process.env.DATABASE_URL)

const prisma = new PrismaClient()

const Depute = objectType({
  name: 'Depute',
  definition(t) {
    t.string('id')
    t.string('first_name')
    t.string('last_name')
  },
})

const Query = objectType({
  name: 'Query',
  definition(t) {
    t.field('depute', {
      type: 'Depute',
      args: {
        id: stringArg({ nullable: false }),
      },
      resolve: (_parent, args, _ctx) => {
        return prisma.depute.findOne({
          where: { id: args.id },
        })
      },
    })
  }, 
})

export const schema = makeSchema({
  types: [Query, Depute, GQLDate],
  outputs: {
    typegen: path.join(process.cwd(), 'pages', 'api', 'nexus-typegen.ts'),
    schema: path.join(process.cwd(), 'pages', 'api', 'schema.graphql')
  },
})


export const config = {
  api: {
    bodyParser: false,
  },
};

export default new ApolloServer({ 
  schema, 
  debug: true
}).createHandler({
    path: '/api/graphql',
});

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
NAllred91commented, Jun 23, 2021

Would it be possible to modify this error to indicate where the file was expected to be?

0reactions
janpiocommented, Jun 23, 2021

Yes, if you open a issue with a current reproduction that triggers the error and describe what it could or should output, we are happy to take a look. Shouldn’T be too hard.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is my domain not automatically generating an SSL ...
The main reason for Vercel not automatically generating an SSL certificate for your domain is because of an incorrect or conflicting CAA record....
Read more >
Errors – Vercel Docs
Because these SSL Certificates are managed by the Vercel platform, they cannot be manually deleted on the Vercel Dashboard – nor via Vercel...
Read more >
Automatic SSL with Vercel and Let's Encrypt
Learn how Vercel uses Let's Encrypt to provision free SSL certificates for all users, automatically.
Read more >
Encryption – Vercel Docs
Every Vercel deployment is served of a HTTPS Connection. ... The SSL certificates for these unique URLs are automatically generated free of charge....
Read more >
Advanced Deployment Protection – Vercel Docs
... for advanced protection of your preview and production deployment URLs. ... who can access your deployments, with password protection and the ability...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found