-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API for proxying discord webhook calls
- Loading branch information
1 parent
9cae2be
commit 22c9b9d
Showing
3 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require("dotenv").config() | ||
const axios = require("axios") | ||
const router = require("express").Router() | ||
|
||
router.get("/:webhookId", async (req, res) => { | ||
// only allow POST | ||
if (req.method === "POST") { | ||
const webhookUrl = `${process.env.DISCORD_WEBHOOK_URL}/${req.params.webhookId}/${process.env.DISCORD_WEBHOOK_TOKEN}` | ||
const webhookData = req.body | ||
try { | ||
await axios.post(webhookUrl, webhookData) | ||
res.status(200).send("Webhook sent successfully") | ||
} catch (error) { | ||
console.error(error) | ||
res.status(500).send("Internal server error") | ||
} | ||
} else { | ||
res.status(405).send("Method not allowed") | ||
} | ||
}) | ||
|
||
module.exports = router |