Files
web-frontend/server/api/graphql.post.ts
2026-04-01 19:10:18 +07:00

28 lines
825 B
TypeScript

export default defineEventHandler(async (event) => {
const config = useRuntimeConfig(event);
const body = await readBody(event);
const cookie = getHeader(event, 'cookie');
const authorization = getHeader(event, 'authorization');
const userId = getHeader(event, 'x-user-id');
const response = await fetch(config.backendGraphqlUrl, {
method: 'POST',
headers: {
'content-type': 'application/json',
...(cookie ? { cookie } : {}),
...(authorization ? { authorization } : {}),
...(userId ? { 'x-user-id': userId } : {}),
},
body: JSON.stringify(body),
});
setResponseStatus(event, response.status);
const contentType = response.headers.get('content-type');
if (contentType) {
setHeader(event, 'content-type', contentType);
}
return await response.json();
});