import type { EventHandlerRequest, H3Event } from 'h3';
export async function apiRequest(event: H3Event<EventHandlerRequest>, path: string) {
const body = await readBody(event);
const { apiUrl, apiKey } = useRuntimeConfig();
try {
return await $fetch(`${apiUrl}/${path}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
query: { 'api-key': apiKey },
body,
});
} catch (error: unknown) {
if (error instanceof Error) {
throw createError({
...error,
statusCode: error.statusCode,
statusMessage: error.statusMessage,
})
}
}
}
import type { EventHandlerRequest, H3Event } from 'h3';
export async function apiRequest(event: H3Event<EventHandlerRequest>, path: string) {
const body = await readBody(event);
const { apiUrl, apiKey } = useRuntimeConfig();
try {
return await $fetch(`${apiUrl}/${path}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
query: { 'api-key': apiKey },
body,
});
} catch (error: unknown) {
if (error instanceof Error) {
throw createError({
...error,
statusCode: error.statusCode,
statusMessage: error.statusMessage,
})
}
}
}