I have encountered an issue with my getServerSideProps()
function, as it is throwing an error when trying to call an external API:
FetchError: request to https://nginx/api/items failed, reason: unable to verify the first certificate
The self-signed certificate used by my Node server is not trusted.
In order to resolve this issue during development, I came across a helpful post on Stack Overflow:
How to configure axios to use SSL certificate?
Following the suggestion in the post, I added rejectUnauthorized: false
to my Axios call like this:
export async function getServerSideProps() {
const res = await fetch('https://nginx/api/items',
{ rejectUnauthorized: false,
method: 'GET',
}
)
const { data } = await res.json()
return { props: { data } }
}
However, despite implementing this change, the error persists.
Are there alternative methods to make my self-signed certificate compatible with Next.js? Although I found solutions for Express, I am unsure how to adapt them for Node within Next.js.