This repository has been archived by the owner on Aug 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
99 lines (82 loc) · 3.29 KB
/
index.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Load the dotenv file \\
require('dotenv').config();
// Now load required modules \\
const cookieParser = require('cookie-parser');
const path = require('path');
const ejs = require('ejs');
const fs = require('fs');
// We are using Fastify to start listening \\
const fastify = require('fastify')({
logger: false
});
fastify.get('/', (req, res) => {
let stream = fs.createReadStream(path.join(__dirname, 'web', 'index.html'));
res.type('text/html').send(stream);
});
fastify.get('/dashboard', (req, res) => {
let stream = fs.createReadStream(path.join(__dirname, 'web', 'wip.html')); // I have no idea when this will be done \\
res.type('text/html').send(stream);
});
fastify.get('/tos', (req, res) => {
let stream = fs.createReadStream(path.join(__dirname, 'web', 'tos.html'));
res.type('text/html').send(stream);
});
fastify.get('/privacy', (req, res) => {
let stream = fs.createReadStream(path.join(__dirname, 'web', 'privacy.html'));
res.type('text/html').send(stream);
});
// URLs \\
// Invite URLs \\
fastify.get('/invite/stable', (req, res) => {
res.redirect(`https://discord.com/api/oauth2/authorize?client_id=${process.env.STABLE_CLIENT_ID}&permissions=2105536231&scope=bot`);
});
fastify.get('/invite/canary', (req, res) => {
res.redirect(`https://discord.com/api/oauth2/authorize?client_id=${process.env.CANARY_CLIENT_ID}&permissions=2105536231&scope=bot`);
});
fastify.get("/invite/alpha", (req, res) => {
res.redirect(`https://discord.com/api/oauth2/authorize?client_id=${process.env.ALPHA_CLIENT_ID}&permissions=2105536231&scope=bot`);
});
fastify.get("/invite/legacy", (req, res) => {
res.redirect(`https://discord.com/api/oauth2/authorize?client_id=${process.env.LEGACY_CLIENT_ID}&permissions=2105536231&scope=bot`);
});
// Support URLs \\
fastify.get('/support', (req, res) => {
res.redirect(`https://discord.gg/${process.env.SUPPORT_INVITE} `);
});
// Github \\
fastify.get('/github', (req, res) => {
res.redirect('https://github.com/FrostbyteSpace');
});
// Assets \\
fastify.get('/assets/:file', (req, res) => {
let stream = fs.createReadStream(path.join(__dirname, 'static', req.params.file));
res.send(stream);
});
// CDN \\
fastify.post('/cdn/', (req, res) => {
// Authenticate with a key from .env \\
if (req.query.key !== process.env.CDN_KEY) {
res.code(401).send({error: "Invalid CDN key"});
} else {
// Write the file \\
fs.writeFile(path.join(__dirname, 'cdn', req.headers.file), req.body, (err) => {
if (err) {
res.code(500).send({error: "Failed to write file"});
} else {
res.code(200).send({success: "File written successfully"});
}
});
}
});
fastify.get('/cdn/:file', (req, res) => {
let stream = fs.createReadStream(path.join(__dirname, 'cdn', req.params.file));
res.send(stream);
});
// Listen on the port provided in the dot env file \\
fastify.listen({port: process.env.PORT, host: "0.0.0.0"}, (err, address) => {
if (err) {
fastify.log.error(err);
process.exit(1);
}
console.log(`Server listening on ${address}`);
})