feat(sep): testing vclaim monitoring

This commit is contained in:
riefive
2025-10-17 14:34:21 +07:00
parent b25b463725
commit 90ab600755
7 changed files with 73 additions and 8 deletions
+15 -5
View File
@@ -1,3 +1,4 @@
import { is } from 'date-fns/locale'
import { defineEventHandler, getCookie, getRequestHeaders, getRequestURL, readBody } from 'h3'
export default defineEventHandler(async (event) => {
@@ -5,11 +6,16 @@ export default defineEventHandler(async (event) => {
const headers = getRequestHeaders(event)
const url = getRequestURL(event)
const config = useRuntimeConfig()
const apiOrigin = config.public.API_ORIGIN
const pathname = url.pathname.replace(/^\/api/, '')
const targetUrl = apiOrigin + pathname + (url.search || '')
const apiOrigin = config.public.API_ORIGIN
const apiVclaim = config.public.VCLAIM
const pathname = url.pathname.replace(/^\/api/, '')
const isVclaim = pathname.includes('/vclaim')
let targetUrl = apiOrigin + pathname + (url.search || '')
if (pathname.includes('/vclaim')) {
targetUrl = apiVclaim + pathname.replace('/vclaim', '') + (url.search || '')
}
const verificationId = headers['verification-id'] as string | undefined
let bearer = ''
@@ -22,7 +28,7 @@ export default defineEventHandler(async (event) => {
const forwardHeaders = new Headers()
if (headers['content-type']) forwardHeaders.set('Content-Type', headers['content-type'])
forwardHeaders.set('Authorization', `Bearer ${bearer}`)
if (!isVclaim) forwardHeaders.set('Authorization', `Bearer ${bearer}`)
let body: any
if (['POST', 'PATCH'].includes(method!)) {
@@ -41,5 +47,9 @@ export default defineEventHandler(async (event) => {
body,
})
if (isVclaim) {
console.log('res:', res)
}
return res
})