cleanup
This commit is contained in:
@@ -14,7 +14,16 @@ export async function clientFetch(url: string, options: RequestInit = {}): Promi
|
||||
...options.headers,
|
||||
};
|
||||
|
||||
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}${url}`, {
|
||||
// Ensure the url doesn't start with a slash if it's going to be appended to a URL that ends with one
|
||||
const cleanUrl = url.startsWith('/') ? url.substring(1) : url;
|
||||
const baseUrl = process.env.NEXT_PUBLIC_API_URL || '/api';
|
||||
|
||||
// Ensure there's only one slash between the base URL and endpoint
|
||||
const fullUrl = baseUrl.endsWith('/')
|
||||
? `${baseUrl}${cleanUrl}`
|
||||
: `${baseUrl}/${cleanUrl}`;
|
||||
|
||||
const res = await fetch(fullUrl, {
|
||||
...options,
|
||||
headers,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user