-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-node.ts
47 lines (40 loc) · 1.07 KB
/
gatsby-node.ts
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
45
46
47
import * as dotenv from "dotenv";
dotenv.config({
path: `.env.${process.env.NODE_ENV}`,
});
import axios from "axios";
import type { SourceNodesArgs } from "gatsby";
export async function sourceNodes({
actions: { createNode, createRedirect },
createContentDigest,
}: SourceNodesArgs) {
const api = process.env.TOP_GG_API ?? "https://top.gg/api";
const token = process.env.TOP_GG_TOKEN ?? "";
const userId = process.env.DISCORD_USER_ID ?? "804245390642642965";
const instance = axios.create({
baseURL: api,
headers: {
Authorization: token,
},
});
const result = await instance.get(`/bots/${userId}/stats`);
createNode({
serverCount: result.data.server_count,
// Required
id: `top-gg-data`,
parent: null,
children: [],
internal: {
type: `Topgg`,
contentDigest: createContentDigest(result.data),
},
});
createRedirect({
fromPath: `/invite`,
toPath: `https://discord.com/oauth2/authorize?client_id=804245390642642965&scope=bot&permissions=2416438336`,
});
createRedirect({
fromPath: `/support`,
toPath: `https://discord.gg/r2YMTMydSF`,
});
}