When attempting to fetch a post on a live next.js 15 site hosted on Fly.io, the URL specified in the fetch request is being altered and leading to a 404 not found error;
The URL shown in the network tab of Chrome's dev tools is:
https://www.rleaguez.com/organizationz/www.rleaguez.com/api/v2/organization
However, when I console log the URL being used, it shows as:
https:www.rleaguez.com/api/v2/organization
Here is the fetch code I am currently using:
const postUrl = 'https:www.rleaguez.com/api/v2/organization';
console.log("🚀 ~ CreateOrg ~ postUrl:", postUrl)
const orgResponse = await fetch(
postUrl,
{
method: 'POST',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify(data),
},
);
If I hardcode the URL within the fetch request as shown below, the post is successful:
const orgResponse = await fetch(
// hardcoded url below is successful
‘https://www.rleaguez.com/api/v2/organization’,
{
method: 'POST',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify(data),
},
);
I'm puzzled as to why the URL changes in the production environment instead of remaining consistent with what I've placed in the code. Any insights would be greatly appreciated!