diff --git a/app.js b/app.js
index 60a2a68..4e7ecdc 100644
--- a/app.js
+++ b/app.js
@@ -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
@@ -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
@@ -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);
\ No newline at end of file
diff --git a/package.json b/package.json
index 4b22ff3..461536d 100644
--- a/package.json
+++ b/package.json
@@ -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": {
diff --git a/readme.md b/readme.md
index 16268c7..3fe0175 100644
--- a/readme.md
+++ b/readme.md
@@ -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)
-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):
diff --git a/src/config.json b/src/config.json
index ba9519b..7bc6e51 100644
--- a/src/config.json
+++ b/src/config.json
@@ -1,7 +1,9 @@
{
"port": 10000,
"token": "",
- "certificate": {
+ "ssl": {
+ "useSSL": true,
+ "port": 11000,
"cert": "",
"key": ""
}
diff --git a/src/util.js b/src/util.js
index a42a727..e82c246 100644
--- a/src/util.js
+++ b/src/util.js
@@ -1,5 +1,6 @@
module.exports = {
error(error, req, res, next) {
+ error.version = server.version;
res.render('error', error);
},
diff --git a/views/error.ejs b/views/error.ejs
index 1e32cad..9dfa1e4 100644
--- a/views/error.ejs
+++ b/views/error.ejs
@@ -39,7 +39,7 @@