UC done v1.0
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
const { sendResponse } = require('../helpers/responseHelper');
|
||||
const {httpStatus, httpStatusMessages} = require('../helpers/httpResponses')
|
||||
function apiKeyValidation(req, res, next) {
|
||||
const apiKey = req.headers['x-api-key'];
|
||||
|
||||
if (apiKey !== req.app.locals.apiKey) {
|
||||
return sendResponse(res, httpStatus.UNAUTHORIZED, httpStatusMessages[httpStatus.UNAUTHORIZED]);
|
||||
}
|
||||
next();
|
||||
}
|
||||
|
||||
module.exports = apiKeyValidation;
|
||||
@@ -0,0 +1,16 @@
|
||||
const { sendResponse } = require('../helpers/responseHelper');
|
||||
const {httpStatus, httpStatusMessages} = require("../helpers/httpResponses");
|
||||
|
||||
function checkJson(req, res, next) {
|
||||
if(req.method === 'GET'){
|
||||
next()
|
||||
}
|
||||
|
||||
if (['POST', 'PUT', 'PATCH'].includes(req.method) && req.headers['content-type'] !== 'application/json') {
|
||||
return sendResponse(res, httpStatus.BAD_REQUEST, httpStatusMessages[httpStatus.BAD_REQUEST]);
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
module.exports = checkJson;
|
||||
@@ -0,0 +1,31 @@
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
|
||||
function SetAdminValuesMiddleware(req, res, next){
|
||||
if(!req.path.startsWith('/admin')){
|
||||
next();
|
||||
return res;
|
||||
}
|
||||
|
||||
try{
|
||||
const configFilePath = path.join(__dirname, '..', 'db', 'config.json');
|
||||
const config = JSON.parse(fs.readFileSync(configFilePath));
|
||||
|
||||
res.locals.adminKey = config.adminKey === undefined ? " " : config.adminKey;
|
||||
res.locals.ceoID = config.ceoID === undefined ? " " : config.ceoID;
|
||||
|
||||
next();
|
||||
|
||||
fs.writeFileSync(configFilePath, JSON.stringify(
|
||||
{
|
||||
adminKey: res.locals.adminKey,
|
||||
ceoID: res.locals.ceoID
|
||||
}, null, 2));
|
||||
return res;
|
||||
} catch(error){
|
||||
console.log(error.message);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SetAdminValuesMiddleware;
|
||||
Reference in New Issue
Block a user