forked from NotionX/react-notion-x
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhook-proxy.ts
More file actions
44 lines (38 loc) · 1.12 KB
/
webhook-proxy.ts
File metadata and controls
44 lines (38 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import type { NextApiRequest, NextApiResponse } from 'next'
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
if (req.method !== 'POST') {
return res.status(405).json({ error: 'Method not allowed' })
}
try {
const { url, payload, headers } = req.body
if (!url || !payload) {
return res.status(400).json({ error: 'Missing url or payload' })
}
// Forward the request to the actual webhook URL
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...headers
},
body: JSON.stringify(payload)
})
const responseData = await response.text()
// Return the response from the webhook
return res.status(response.status).json({
success: response.ok,
status: response.status,
statusText: response.statusText,
data: responseData
})
} catch (err) {
console.error('Webhook proxy error:', err)
return res.status(500).json({
error: 'Failed to forward webhook',
message: err instanceof Error ? err.message : 'Unknown error'
})
}
}