mirror of
https://github.com/TheGreyDiamond/elevatormapRewritten.git
synced 2025-07-18 02:23:50 +02:00
Removed unused lines, Fixed up some linting errors, more code documentation, updated some dep versions, and fixed error in package.json
This commit is contained in:
@ -10,7 +10,8 @@
|
|||||||
"plugin:@typescript-eslint/recommended"
|
"plugin:@typescript-eslint/recommended"
|
||||||
],
|
],
|
||||||
"rules": {
|
"rules": {
|
||||||
"@typescript-eslint/no-var-requires": 0
|
"@typescript-eslint/no-var-requires": 0,
|
||||||
|
"no-control-regex": 0
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
49
index.ts
49
index.ts
@ -5,7 +5,6 @@ const Eta = require("eta");
|
|||||||
const winston = require("winston");
|
const winston = require("winston");
|
||||||
const mysql = require("mysql");
|
const mysql = require("mysql");
|
||||||
const bodyParser = require("body-parser");
|
const bodyParser = require("body-parser");
|
||||||
// const csp = require(`helmet`);
|
|
||||||
const session = require("express-session");
|
const session = require("express-session");
|
||||||
const nodemailer = require("nodemailer");
|
const nodemailer = require("nodemailer");
|
||||||
|
|
||||||
@ -32,34 +31,12 @@ logger.add(
|
|||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
app.use(csp.contentSecurityPolicy({
|
|
||||||
useDefaults: true,
|
|
||||||
contentSecurityPolicy: false,
|
|
||||||
crossOriginEmbedderPolicy: false,
|
|
||||||
directives: {
|
|
||||||
"default-src": [`'self'`],
|
|
||||||
"img-src": [`'self'`],
|
|
||||||
scriptSrc: [`'self'`, `https://hcaptcha.com`, `https://*.hcaptcha.com`, `https://*.fontawesome.com`, "unsafe-inline", "unsafe-eval","'unsafe-inline'"],
|
|
||||||
"script-src-attr": [`'self'`, `https://hcaptcha.com`, `https://*.hcaptcha.com`, `https://*.fontawesome.com`, "unsafe-inline", "unsafe-eval"],
|
|
||||||
"frame-src": [`'self'`, `https://hcaptcha.com`, `https://*.hcaptcha.com`],
|
|
||||||
"style-src": [`'self'`, `https://hcaptcha.com`, `https://*.hcaptcha.com`, `https://*.fontawesome.com`, `'unsafe-inline'`],
|
|
||||||
"connect-src": [`'self'`, `https://hcaptcha.com`, `https://*.hcaptcha.com`, `https://*.fontawesome.com`],
|
|
||||||
"font-src": [`'self'`, `https://*.fontawesome.com`],
|
|
||||||
},
|
|
||||||
|
|
||||||
}))
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
const startUpTime = Math.floor(new Date().getTime() / 1000);
|
const startUpTime = Math.floor(new Date().getTime() / 1000);
|
||||||
|
|
||||||
|
// Skeleton Variables
|
||||||
let fontawesomeKey = "";
|
let fontawesomeKey = "";
|
||||||
let mapboxAccessToken = "";
|
let mapboxAccessToken = "";
|
||||||
let mysqlData = { "user": "", "password": "", "database": "", "allowCreation": false };
|
let mysqlData = { "user": "", "password": "", "database": "", "allowCreation": false };
|
||||||
let hCaptcha = { "sitekey": "", "secret": "" };
|
|
||||||
let mailConf = { "host": "", "port": 0, "username": "", "password": "" };
|
let mailConf = { "host": "", "port": 0, "username": "", "password": "" };
|
||||||
let serverAdress = "";
|
let serverAdress = "";
|
||||||
let cookieSecret = ""
|
let cookieSecret = ""
|
||||||
@ -94,12 +71,14 @@ try {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Express (server) preperation
|
||||||
app.use(express.static("static"));
|
app.use(express.static("static"));
|
||||||
|
|
||||||
app.use(bodyParser.urlencoded({ extended: false }));
|
app.use(bodyParser.urlencoded({ extended: false }));
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
app.use(session({ secret: cookieSecret }));
|
app.use(session({ secret: cookieSecret }));
|
||||||
app.use(function (req, res, next) {
|
app.use(function (req, res, next) {
|
||||||
|
// PreShow Errorpage handler
|
||||||
const pathesWhichRequireDB = ["map", "login", "register"];
|
const pathesWhichRequireDB = ["map", "login", "register"];
|
||||||
const pathesWhichRequireLogin = ["createElevator"];
|
const pathesWhichRequireLogin = ["createElevator"];
|
||||||
const path = req.path
|
const path = req.path
|
||||||
@ -169,9 +148,9 @@ app.use(function (req, res, next) {
|
|||||||
} else {
|
} else {
|
||||||
console.log("Stopped further exec of route")
|
console.log("Stopped further exec of route")
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Mail preperation
|
||||||
const transport = nodemailer.createTransport({
|
const transport = nodemailer.createTransport({
|
||||||
host: mailConf.host,
|
host: mailConf.host,
|
||||||
port: mailConf.port,
|
port: mailConf.port,
|
||||||
@ -179,15 +158,12 @@ const transport = nodemailer.createTransport({
|
|||||||
secure: false,
|
secure: false,
|
||||||
debug: true,
|
debug: true,
|
||||||
disableFileAccess: true,
|
disableFileAccess: true,
|
||||||
//authMethod: "START TLS",
|
|
||||||
auth: {
|
auth: {
|
||||||
user: mailConf.username,
|
user: mailConf.username,
|
||||||
pass: mailConf.password,
|
pass: mailConf.password,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
//let transporter = nodemailer.createTransport(transport)
|
|
||||||
//console.log(transport.host)
|
|
||||||
logger.info("Testing SMTP connection");
|
logger.info("Testing SMTP connection");
|
||||||
transport.verify(function (error) {
|
transport.verify(function (error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -197,9 +173,6 @@ transport.verify(function (error) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use(session({ secret: cookieSecret }));
|
|
||||||
|
|
||||||
|
|
||||||
// Basic defines for html
|
// Basic defines for html
|
||||||
const metainfo = {
|
const metainfo = {
|
||||||
author: "TheGreydiamond",
|
author: "TheGreydiamond",
|
||||||
@ -220,8 +193,6 @@ let con = mysql.createConnection({
|
|||||||
database: mysqlData.database,
|
database: mysqlData.database,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function checkIfMySQLStructureIsReady() {
|
function checkIfMySQLStructureIsReady() {
|
||||||
if (mysqlIsUpAndOkay) {
|
if (mysqlIsUpAndOkay) {
|
||||||
// Only if MySQL is ready
|
// Only if MySQL is ready
|
||||||
@ -288,7 +259,7 @@ con.connect(function (err) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Routes
|
// Routes
|
||||||
app.get("/", function (req, res) {
|
app.get("/", function (req, res) { // Index page
|
||||||
const data = fs.readFileSync("templates/index.html", "utf8");
|
const data = fs.readFileSync("templates/index.html", "utf8");
|
||||||
res.send(
|
res.send(
|
||||||
Eta.render(data, {
|
Eta.render(data, {
|
||||||
@ -300,7 +271,7 @@ app.get("/", function (req, res) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/map", function (req, res) {
|
app.get("/map", function (req, res) { // Map page showing all elevators
|
||||||
const data = fs.readFileSync("templates/map.html", "utf8");
|
const data = fs.readFileSync("templates/map.html", "utf8");
|
||||||
res.send(
|
res.send(
|
||||||
Eta.render(data, {
|
Eta.render(data, {
|
||||||
@ -314,7 +285,7 @@ app.get("/map", function (req, res) {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/createElevator", function (req, res) {
|
app.get("/createElevator", function (req, res) { // Page to create a new elvator
|
||||||
const data = fs.readFileSync("templates/createElevator.html", "utf8");
|
const data = fs.readFileSync("templates/createElevator.html", "utf8");
|
||||||
res.send(
|
res.send(
|
||||||
Eta.render(data, {
|
Eta.render(data, {
|
||||||
@ -331,9 +302,9 @@ require('./routes/api.route.ts')(app, con, mysqlIsUpAndOkay, logger, metainfo);
|
|||||||
require('./routes/debug.route.ts')(app, con, logger, metainfo);
|
require('./routes/debug.route.ts')(app, con, logger, metainfo);
|
||||||
require('./routes/auth.route.ts')(app, con, logger, metainfo, jsonConfigGlobal);
|
require('./routes/auth.route.ts')(app, con, logger, metainfo, jsonConfigGlobal);
|
||||||
|
|
||||||
// Some loops for handeling stuff
|
// Some loops for handeling stuff,
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
if (mysqlIsUpAndOkay == false) {
|
if (mysqlIsUpAndOkay == false) { // SQL reconnect
|
||||||
logger.warn("Retrying to connect to MySQL");
|
logger.warn("Retrying to connect to MySQL");
|
||||||
con = mysql.createConnection({
|
con = mysql.createConnection({
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
@ -353,7 +324,7 @@ setInterval(() => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, 60000);
|
}, 60*1000); // Every minute
|
||||||
|
|
||||||
// App start
|
// App start
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
|
4261
package-lock.json
generated
4261
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@ -17,19 +17,19 @@
|
|||||||
"url": "git+https://github.com/TheGreyDiamond/elevatormapRewritten.git"
|
"url": "git+https://github.com/TheGreyDiamond/elevatormapRewritten.git"
|
||||||
},
|
},
|
||||||
"author": "TheGreydiamond",
|
"author": "TheGreydiamond",
|
||||||
"license": "ISC",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/TheGreyDiamond/elevatormapRewritten/issues"
|
"url": "https://github.com/TheGreyDiamond/elevatormapRewritten/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/TheGreyDiamond/elevatormapRewritten#readme",
|
"homepage": "https://github.com/TheGreyDiamond/elevatormapRewritten",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bcrypt": "^5.0.1",
|
"bcrypt": "^5.0.1",
|
||||||
"body-parser": "^1.19.0",
|
"body-parser": "^1.19.0",
|
||||||
"eta": "^1.12.2",
|
"eta": "^1.12.3",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"express-session": "^1.17.2",
|
"express-session": "^1.17.2",
|
||||||
"greeting-time": "^1.0.0",
|
"greeting-time": "^1.0.0",
|
||||||
"hcaptcha": "0.0.2",
|
"hcaptcha": "0.1.0",
|
||||||
"helmet": "^4.6.0",
|
"helmet": "^4.6.0",
|
||||||
"multer": "^1.4.2",
|
"multer": "^1.4.2",
|
||||||
"mysql": "^2.18.1",
|
"mysql": "^2.18.1",
|
||||||
@ -38,9 +38,9 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^16.0.0",
|
"@types/node": "^16.0.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.21.0",
|
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
||||||
"@typescript-eslint/parser": "^4.21.0",
|
"@typescript-eslint/parser": "^4.33.0",
|
||||||
"eslint": "^7.26.0",
|
"eslint": "^7.32.0",
|
||||||
"eslint-config-strongloop": "^2.1.0",
|
"eslint-config-strongloop": "^2.1.0",
|
||||||
"typescript": "^4.2.4"
|
"typescript": "^4.2.4"
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,6 @@ module.exports = function (app, con, mysqlIsUpAndOkay, logger) {
|
|||||||
|
|
||||||
app.get("/api/resolveNameById", function (req, res) {
|
app.get("/api/resolveNameById", function (req, res) {
|
||||||
if (req.query.id != undefined && req.query.id != "") {
|
if (req.query.id != undefined && req.query.id != "") {
|
||||||
|
|
||||||
const sql = "SELECT username FROM users WHERE id=?";
|
const sql = "SELECT username FROM users WHERE id=?";
|
||||||
con.query(sql, [req.query.id], function (err, result) {
|
con.query(sql, [req.query.id], function (err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
Reference in New Issue
Block a user