mirror of
https://github.com/20kaushik02/express-sequelize-backend-template.git
synced 2026-01-25 07:14:06 +00:00
boom!
overall: formatting check, jsdoc type hints, express res/return stuff utils - changes in logger, dateformatter and removed unneeded ones .env file changes license check, readme update package.json update - version, deps, URLs server cleanup sequelize config check
This commit is contained in:
@@ -1 +1 @@
|
||||
## Middleware - functionalities that must be in the middle of the API route control flow
|
||||
# Middleware - functionalities that must be in the middle of the API route control flow
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const typedefs = require("../typedefs");
|
||||
const logger = require("../utils/logger")(module);
|
||||
|
||||
const typedefs = require("../typedefs");
|
||||
|
||||
const creds = JSON.parse(process.env.ADMIN_CREDS);
|
||||
|
||||
/**
|
||||
@@ -11,7 +12,7 @@ const creds = JSON.parse(process.env.ADMIN_CREDS);
|
||||
*/
|
||||
const adminQueryCreds = async (req, res, next) => {
|
||||
try {
|
||||
/** @type {JSON} */
|
||||
/** @type {any} */
|
||||
const { user, access } = req.query;
|
||||
if (creds[user] === access) {
|
||||
logger.info("Admin access - " + user);
|
||||
@@ -20,15 +21,17 @@ const adminQueryCreds = async (req, res, next) => {
|
||||
else {
|
||||
// we do a bit of trolling here
|
||||
const unauthIP = req.headers['x-real-ip'] || req.ip
|
||||
res.status(401).send("Intruder alert. IP address: " + unauthIP);
|
||||
logger.warn("Intruder alert.", { ip: unauthIP });
|
||||
return res.status(401).send("Intruder alert. IP address: " + unauthIP);
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
res.sendStatus(500);
|
||||
logger.error("adminQueryCreds", { error });
|
||||
return res.status(500).send({ message: "Server Error. Try again." });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
adminQueryCreds,
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
const fetch = require("cross-fetch");
|
||||
|
||||
const typedefs = require("../typedefs");
|
||||
const logger = require("../utils/logger")(module);
|
||||
|
||||
const typedefs = require("../typedefs");
|
||||
|
||||
/**
|
||||
* Google ReCAPTCHA v2 verification
|
||||
*
|
||||
@@ -19,18 +20,20 @@ const verifyCaptcha = async (req, res, next) => {
|
||||
const captchaResp = await fetch(verifyCaptchaURL);
|
||||
const captchaData = await captchaResp.json();
|
||||
if (captchaData.success !== undefined && !captchaData.success) {
|
||||
logger.error("Recaptcha", { captchaData });
|
||||
return res.status(403).send({
|
||||
res.status(403).send({
|
||||
message: "Failed captcha verification"
|
||||
});
|
||||
logger.error("Recaptcha", { captchaData });
|
||||
return;
|
||||
}
|
||||
next();
|
||||
} catch (error) {
|
||||
logger.error("Error", { error });
|
||||
return res.status(500).send({ message: "Server Error. Try again." });
|
||||
res.sendStatus(500);
|
||||
logger.error("verifyCaptcha", { error });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
verifyCaptcha
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user