api/routes/op.post.ts

4c266e755e45d573c74471477f8f454db2d63903
wotaku/api/routes/op.post.ts
taskylizard wotaku 2bea9706e6c 1 year ago

36 lines · 959 bytes

 1/**
 2 *  All Rights Reserved
 3 *
 4 *  Copyright (c) 2025 taskylizard
 5 *
 6 *  All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
 7 */
 8import { joinURL } from 'ufo'
 9
10export default defineEventHandler(async (event) => {
11  const config = useRuntimeConfig(event).op
12
13  try {
14    const target = joinURL(config.url, 'track')
15
16    const headers = {
17      'X-Forwarded-For': getRequestIP(event, { xForwardedFor: true }),
18      'Content-Type': 'application/json',
19      'openpanel-client-id': config.id
20    }
21
22    headers['openpanel-sdk-name'] = 'nitro'
23    headers['openpanel-sdk-version'] = '1.0.0'
24
25    return proxyRequest(event, target, {
26      headers
27    })
28  } catch (error) {
29    console.error(error)
30
31    throw createError({
32      statusCode: 502,
33      message: 'Failed to proxy request'
34    })
35  }
36})
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form