This commit is contained in:
NotII
2025-03-23 21:25:37 +00:00
parent dc51901c5c
commit 8d7d9b9e1c
5 changed files with 74 additions and 80 deletions

View File

@@ -13,9 +13,21 @@ export async function fetchServer<T = unknown>(
if (!authToken) redirect('/login');
// Ensure the endpoint doesn't start with a slash if it's going to be appended to a URL that ends with one
const cleanEndpoint = endpoint.startsWith('/') ? endpoint.substring(1) : endpoint;
try {
console.log(`${endpoint}`)
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}${endpoint}`, {
// Make sure we're using a complete URL (protocol + hostname + path)
const apiUrl = process.env.SERVER_API_URL || 'https://internal-api.inboxi.ng/api';
// Ensure there's only one slash between the base URL and endpoint
const url = apiUrl.endsWith('/')
? `${apiUrl}${cleanEndpoint}`
: `${apiUrl}/${cleanEndpoint}`;
console.log(`Making server request to: ${url}`);
const res = await fetch(url, {
...options,
headers: {
'Content-Type': 'application/json',