Files
simrsx-fe/server/api/[...req].ts
Khafid Prayoga 6ad99d45f2 Fix/linter (#10)
* fix(style): formatting inconsistencies across codebase

- Remove trailing semicolons from TypeScript imports
- Fix Vue template indentation and line breaks
- Standardize component attribute formatting
- Remove unnecessary empty lines
- Reorder import statements for consistency

* chore: update import path and add editorconfig

Update SidebarNavLink import path to match new component structure and add standard editorconfig for consistent code formatting
2025-08-27 13:06:40 +07:00

46 lines
1.4 KiB
TypeScript

import process from 'node:process'
import { defineEventHandler, getCookie, getRequestHeaders, getRequestURL, readBody } from 'h3'
const API_ORIGIN = process.env.API_ORIGIN as string
export default defineEventHandler(async (event) => {
const { method } = event.node.req
const headers = getRequestHeaders(event)
const url = getRequestURL(event)
const pathname = url.pathname.replace(/^\/api/, '')
const targetUrl = API_ORIGIN + pathname + (url.search || '')
const verificationId = headers['verification-id'] as string | undefined
let bearer = ''
if (verificationId) {
bearer = getCookie(event, `Verification-${verificationId}`) || ''
if (!bearer) bearer = getCookie(event, 'authentication') || ''
} else {
bearer = getCookie(event, 'authentication') || ''
}
const forwardHeaders = new Headers()
if (headers['content-type']) forwardHeaders.set('Content-Type', headers['content-type'])
forwardHeaders.set('Authorization', `Bearer ${bearer}`)
let body: any
if (['POST', 'PATCH'].includes(method!)) {
if (headers['content-type']?.includes('multipart/form-data')) {
body = await readBody(event)
} else {
body = await readBody(event)
forwardHeaders.set('Content-Type', 'application/json')
body = JSON.stringify(body)
}
}
const res = await fetch(targetUrl, {
method,
headers: forwardHeaders,
body,
})
return res
})