It is exactly as you assume:
I have a directory called certs in the root of the git repository that I am building from and it contains the certificate(s).
I have setup NODE_EXTRA_CA_CERTS as you have suggested. Now I’m getting:
1:35:29 PM: Warning: Ignoring extra certs from `/opt/build/repo/certs/intermediate.pem`, load failed: error:02001002:system library:fopen:No such file or directory
There is the possibility this isn’t possible. I can neither confirm nor deny. With luck a Support Engineer (or other community member) can provide a solid answer.
I did some debugging and it turns out that if using nextjs, netlify-functions would run in /var/task/nextPage/pages/api.
So I have moved certificate to pages/api/intermediate.pem and configured NODE_EXTRA_CA_CERTS as NODE_EXTRA_CA_CERTS = /var/task/nextPage/pages/api/intermediate.pem but it still doesn’t work for the same reason.
You are trying to access/use this certificate in a function?
In that case, you won’t want to use an environment variable. You will need to require it in the function so it is bundled with the function at build time. E.g.
const cert = require('./certifice.pem');
Where certificate.pem is in the same directory as the function requiring it.
(Note: I see in your original post you mention serverless function. Apologies.)
Many thanks for all your help, @coelmay.
It looks like netxjs is not shipping the whole folder-content, so the certificate gets removed during build process (or not being shipped, depends on how you see it). So I don’t even get this approach to work in my local environment, unfortunately.
Regardless, thank you so much for all your effort!