Search code examples
javascriptreactjsproxygatsby

Error with Gatsby when trying to proxy request


I am getting an error when trying to proxy my dev url through Gatsby. In my gatsby-config.js I have:

  proxy: [
    {
      prefix: '/myaccount',
      url: 'https://www-dev.site.com',
    },
  ],

Gatsby Proxy Error Screenshot

Error when trying to proxy request "/myaccount/" to "https://www-dev.site.com/myaccount/" write EPROTO 4584046080:error:14094458:SSL routines:ssl3_read_bytes:tlsv1 unrecognized name:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1544:SSL alert number 112

RequestError: write EPROTO 4555591168:error:14094458:SSL routines:ssl3_read_bytes:tlsv1 unrecognized name:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1544:SSL alert number 112

This was working and all of a sudden stopped.


Solution

  • As it has been said, it looks like a certificate issue (because of the SSL). Without more implementation details it's difficult to guess if a proposed solution will work on your scenario but you can try setting the security as false (secure: false) to don't reject self-signed certificates. In your gatsby-config.js:

    const { createProxyMiddleware } = require("http-proxy-middleware") 
    
    module.exports = {
      developMiddleware: app => {
        app.use(
          "/.netlify/functions/",
          createProxyMiddleware({
            target: "http://localhost:9000",
            secure: false, 
            pathRewrite: {
              "/.netlify/functions/": "",
            },
          })
        )
      },
    

    Docs: https://www.gatsbyjs.com/docs/api-proxy/#self-signed-certificates

    Tweak it to adapt it to your needs, replacing /.netlify/functions/ for your API endpoint.