NR Editor constently loses connections and Trying to setup NR https using the https key and cert for a docker image running in pivotal cloudFoundry backed by AWS to resolve

Pivotal uses instance Identity Credentials and they are surfaced with the environment variables I during run time I convert them using openssl as follows to get the RSA key and the Certificate only section as follows:
openssl rsa -in $CF_INSTANCE_KEY > key.pem for the key file
openssl x509 -in $CF_INSTANCE_CERT -out cert.pem

I added them to the settings.js under the function for https as follows

    https: function() {
         // This function should return the options object, or a Promise
         // that resolves to the options object
         return {
             key: require("fs").readFileSync('key.pem'),
             cert: require("fs").readFileSync('cert.pem')
         }
     },

I deployed the changes and node red launches and runs but get 502 gateway errors when I try to hit the hostname.
If I comment out the http config
Node red launches in https without https configured in node red which then displays constent messages stating that node-red ost connection
Many errors in the browser console not found

Trying to get this to function please help

Can someone provide guidance with this