Add discord endpoint
This commit is contained in:
parent
8261a31328
commit
f9ddc3513f
22
index.js
22
index.js
|
@ -491,6 +491,28 @@ app.get("/api/v1/directory", (req, res) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Other public endpoints that need special handling
|
||||||
|
discordInviteCache = {time: 0, url: ""};
|
||||||
|
|
||||||
|
app.get("/discord", (req, res) => {
|
||||||
|
// fetch from process.env.WIDGET_URL, get json body, redirect to body.instant_invite. Cache url for 5 minutes
|
||||||
|
if (Date.now() - discordInviteCache.time < 300000) {
|
||||||
|
res.redirect(discordInviteCache.url);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fetch(process.env.WIDGET_URL)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
discordInviteCache.time = Date.now();
|
||||||
|
discordInviteCache.url = data.instant_invite;
|
||||||
|
res.redirect(data.instant_invite);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error fetching discord invite:', error);
|
||||||
|
res.status(500).send('Internal server error');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Query to get a route
|
// Query to get a route
|
||||||
app.get('/api/v1/route/:apiKey/:ani/:number', (req, res) => {
|
app.get('/api/v1/route/:apiKey/:ani/:number', (req, res) => {
|
||||||
const apiKey = req.params.apiKey;
|
const apiKey = req.params.apiKey;
|
||||||
|
|
Loading…
Reference in a new issue