Skip to content

Commit

Permalink
Added option to enable/disable https, added a version to the footer, …
Browse files Browse the repository at this point in the history
…added the 'Team'-Badge
  • Loading branch information
RappyTV committed Feb 27, 2023
1 parent c2890ae commit c794478
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 19 deletions.
32 changes: 21 additions & 11 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,37 @@ const express = require(`express`);
global.server = {};
const app = express();
const https = require(`https`);
const http = require(`http`);
const path = require(`path`);
const axios = require(`axios`);
const { readFileSync } = require("fs");
const { readFileSync, existsSync } = require("fs");

server.cfg = require(`./src/config.json`);
server.redirects = require(`./src/redirects.json`);
server.util = require(`./src/util`);
server.version = require(`./package.json`).version;

const options = {};

if(server.cfg.token.trim() == ``) {
console.log(`[ERROR] Please provide a valid token in src/config.json!`);
process.exit(1);
}

const options = {
cert: readFileSync(server.cfg.certificate.cert),
key: readFileSync(server.cfg.certificate.key)
if(server.cfg.ssl.useSSL) {
if(!existsSync(server.cfg.ssl.cert) || !existsSync(server.cfg.ssl.key)) {
console.log(`[ERROR] Invalid certificate or private key path!\n[INFO] If you don't want to use an SSL certificate please disable the option in src/config.json!`);
process.exit(1);
}
options.cert = readFileSync(server.cfg.ssl.cert);
options.key = readFileSync(server.cfg.ssl.key);
}

server.https = https.createServer(options, app).listen(server.cfg.port, () => {
console.log(`[SERVER] HTTPS listening on Port ${server.cfg.port}!`);
if(server.cfg.ssl.useSSL) server.https = https.createServer(options, app).listen(server.cfg.ssl.port, () => {
console.log(`[SERVER] HTTPS listening on port ${server.cfg.ssl.port}!`);
});

server.http = http.createServer(app).listen(server.cfg.port, () => {
console.log(`[SERVER] HTTP listening on port ${server.cfg.port}`);
});

// Views
Expand All @@ -30,17 +41,16 @@ app.set(`views`, path.join(__dirname, `views`));
app.use(express.static(`./public`));

app.use((req, res, next) => {
if(process.env.NODE_ENV != 'development' && !req.secure) {
if(process.env.NODE_ENV != 'development' && !req.secure && server.cfg.ssl.useSSL) {
return res.redirect("https://" + req.headers.host + req.url);
}
if(req.headers.host.includes(`rappytv.com:10000`)) return res.redirect(`https://id.rappytv.com`);

next();
});

// Index page
app.get(`/`, (req, res) => {
res.status(200).render(`index`);
res.status(200).render(`index`, { version: server.version });
});

// Load pages without route
Expand Down Expand Up @@ -76,7 +86,7 @@ app.get(`/:id`, async (req, res, next) => {
const created = new Date(server.util.getTimestamp(id)).toUTCString();
const color = data.banner_color;

res.render(`user`, { pfp, banner, id, tag, bot: data.bot, badges, created, color });
res.render(`user`, { pfp, banner, id, tag, bot: data.bot, badges, created, color, version: server.version });
});

app.use(server.util.error);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "discord.id",
"version": "1.0.0",
"version": "1.2.0",
"main": "app.js",
"description": "This is an inofficial remake of discord.id",
"repository": {
Expand Down
12 changes: 9 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ Your [src/config.json](https://github.com/UltronDevelopment/discord.id/blob/mast
{
"port": 10000,
"token": "",
"certificate": {
"ssl": {
"useSSL": true,
"port": 11000,
"cert": "",
"key": ""
}
}
```
Just insert a bot token (you can't fetch users without a bot) and set the port to your desired port the website should run on (only https)<br>
Then insert the path to your certificate into `certificate.cert` and the path to your key to `certificate.key`.
- `port` - The http port
- `token` - Your bot's token (you can't fetch users without a bot token)
- `ssl.useSSL` - If the server should use an SSL certificate
- `ssl.port` - The https port
- `ssl.cert` - The path to your fullchain certificate file
- `ssl.key` - The path to your private key file

### 3️⃣ Redirects
To redirect custom paths to a specific url add an object like this to the array in [src/redirects.json](https://github.com/UltronDevelopment/discord.id/blob/master/src/redirects.json):
Expand Down
4 changes: 3 additions & 1 deletion src/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"port": 10000,
"token": "",
"certificate": {
"ssl": {
"useSSL": true,
"port": 11000,
"cert": "",
"key": ""
}
Expand Down
1 change: 1 addition & 0 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
error(error, req, res, next) {
error.version = server.version;
res.render('error', error);
},

Expand Down
2 changes: 1 addition & 1 deletion views/error.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</div>
</div>
<div class="footerarea">
<p id="footer" style="margin: 0 0 0 0;">© <a href="https://www.rappytv.com" style="color: #91D6FF !important;">RappyTV#6969</a> | <a href="https://github.com/UltronDevelopment/discord.id">Check this project out on GitHub</a> | Not affiliated with Discord, Inc.</p>
<p id="footer" style="margin: 0 0 0 0;">© <a href="https://www.rappytv.com" style="color: #91D6FF !important;">RappyTV#6969</a> | <a href="https://github.com/UltronDevelopment/discord.id">Check this project out on GitHub</a> | <span style="color: #ffa09e;">Version <%= locals.version %></span> | Not affiliated with Discord, Inc.</p>
</div>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</div>
</div>
<div class="footerarea">
<p id="footer" style="margin: 0 0 0 0;">© <a href="https://www.rappytv.com" style="color: #91D6FF !important;">RappyTV#6969</a> | <a href="https://github.com/UltronDevelopment/discord.id">Check this project out on GitHub</a> | Not affiliated with Discord, Inc.</p>
<p id="footer" style="margin: 0 0 0 0;">© <a href="https://www.rappytv.com" style="color: #91D6FF !important;">RappyTV#6969</a> | <a href="https://github.com/UltronDevelopment/discord.id">Check this project out on GitHub</a> | <span style="color: #ffa09e;">Version <%= locals.version %></span> | Not affiliated with Discord, Inc.</p>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion views/user.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
</div>
</div>
<div class="footerarea">
<p id="footer" style="margin: 0 0 0 0;">© <a href="https://www.rappytv.com" style="color: #91D6FF !important;">RappyTV#6969</a> | <a href="https://github.com/UltronDevelopment/discord.id">Check this project out on GitHub</a> | Not affiliated with Discord, Inc.</p>
<p id="footer" style="margin: 0 0 0 0;">© <a href="https://www.rappytv.com" style="color: #91D6FF !important;">RappyTV#6969</a> | <a href="https://github.com/UltronDevelopment/discord.id">Check this project out on GitHub</a> | <span style="color: #ffa09e;">Version <%= locals.version %></span> | Not affiliated with Discord, Inc.</p>
</div>
</div>

Expand Down

0 comments on commit c794478

Please sign in to comment.