Refactor limqRequest function to remove default localhost URL and add CORS mode for API requests.

This commit is contained in:
2025-04-23 09:16:29 +08:00
parent a8c94c9621
commit ced29201da

View File

@@ -21,7 +21,7 @@ export async function limqRequest<T = unknown>(
throw new Error('No active session. User must be authenticated.'); throw new Error('No active session. User must be authenticated.');
} }
const baseUrl = process.env.NEXT_PUBLIC_LIMQ_API || 'http://localhost:3005'; const baseUrl = process.env.NEXT_PUBLIC_LIMQ_API;
const url = `${baseUrl}${endpoint.startsWith('/') ? endpoint : '/' + endpoint}`; const url = `${baseUrl}${endpoint.startsWith('/') ? endpoint : '/' + endpoint}`;
const options: RequestInit = { const options: RequestInit = {
@@ -29,7 +29,8 @@ export async function limqRequest<T = unknown>(
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Authorization': `Bearer ${session.access_token}` 'Authorization': `Bearer ${session.access_token}`
} },
mode: 'cors'
}; };
if (data && (method === 'POST' || method === 'PUT')) { if (data && (method === 'POST' || method === 'PUT')) {