Skip to content

Commit dafa45e

Browse files
committed
Fix webhook proxy endpoint
1 parent 6afd8fb commit dafa45e

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

src/server/routes/webhookProxy.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,16 @@ require("dotenv").config()
22
const axios = require("axios")
33
const router = require("express").Router()
44

5-
router.get("/:webhookId", async (req, res) => {
6-
console.log(req)
7-
// only allow POST
8-
if (req.method === "POST") {
9-
const webhookUrl = `${process.env.DISCORD_WEBHOOK_URL}/${req.params.webhookId}/${process.env.DISCORD_WEBHOOK_TOKEN}`
10-
const webhookData = req.body
11-
try {
12-
console.log('Sending webhook', webhookUrl, webhookData)
13-
await axios.post(webhookUrl, webhookData, { params: req.query })
14-
console.log('Webhook sent successfully')
15-
res.status(200).send("Webhook sent successfully")
16-
return
17-
} catch (error) {
18-
console.error(error)
19-
res.status(500).send("Internal server error")
20-
return
21-
}
22-
} else {
23-
res.status(405).send("Method not allowed")
5+
router.post("/:webhookId", async (req, res) => {
6+
const webhookUrl = `${process.env.DISCORD_WEBHOOK_URL}/${req.params.webhookId}/${process.env.DISCORD_WEBHOOK_TOKEN}`
7+
const webhookData = req.body
8+
try {
9+
await axios.post(webhookUrl, webhookData, { params: req.query })
10+
res.status(200).send("Webhook sent successfully")
11+
return
12+
} catch (error) {
13+
console.error(error)
14+
res.status(500).send("Internal server error")
2415
return
2516
}
2617
})

0 commit comments

Comments
 (0)