Compare commits

..

4 Commits

Author SHA1 Message Date
Fred Boniface 9d51d4e45e Bump version
Signed-off-by: Fred Boniface <fred@fjla.uk>
2024-04-29 11:21:31 +01:00
Fred Boniface fde37814a7 Add delay to LDB retry after ENOTFOUND error.
Signed-off-by: Fred Boniface <fred@fjla.uk>
2024-04-29 11:20:27 +01:00
Fred Boniface 8fa0cf775f Fix LDB Cache, so when data is missing, nothing is cached
Signed-off-by: Fred Boniface <fred@fjla.uk>
2024-04-29 11:16:40 +01:00
Fred Boniface afa4ad7915 Remove logging succesful authentications - fills logs with useless lines
Signed-off-by: Fred Boniface <fred@fjla.uk>
2024-04-29 11:10:41 +01:00
5 changed files with 18 additions and 8 deletions

View File

@ -5,7 +5,7 @@ interface versions {
const version: versions = { const version: versions = {
api: ["/api/v2"], api: ["/api/v2"],
app: "2024.04.3", app: "2024.04.4",
}; };
module.exports = version; module.exports = version;

View File

@ -9,7 +9,7 @@ async function getTrain(req, res, next) {
err.status = 401; err.status = 401;
throw err; throw err;
} }
setCache(res, "private", 180) setCache(res, "private", 240)
let type = req.params.searchType; let type = req.params.searchType;
let id = req.params.id; let id = req.params.id;
try { try {
@ -45,8 +45,14 @@ async function getStation(req, res, next) {
err.status = 401; err.status = 401;
return next(err); return next(err);
} }
setCache(res, "public", 120) const data = await ldb.get(id, true);
res.json(await ldb.get(id, true)); // Only cache if data is present
if (data.data) {
setCache(res, "public", 120);
} else {
setCache(res, "no-store", 120);
}
res.json(data);
} else { } else {
setCache(res, "public", 240) setCache(res, "public", 240)
res.json(await ldb.get(id, false)); res.json(await ldb.get(id, false));

View File

@ -18,6 +18,7 @@ async function getReasonCode(req, res, next) {
} catch (err) { } catch (err) {
console.error("ERROR", err.message); console.error("ERROR", err.message);
err.status = 500; err.status = 500;
setCache(res, "no-store", 5)
next(err); next(err);
} }
} }

View File

@ -21,21 +21,19 @@ module.exports = async function authCheck(
} else if (typeof id === "string") { } else if (typeof id === "string") {
const authCheck = (await isAuthed(id)) || false; const authCheck = (await isAuthed(id)) || false;
if (authCheck) { if (authCheck) {
// Authenticate
req.isAuthed = true; req.isAuthed = true;
logger.info("auth.middleware: Authentication Successful");
next(); next();
} else { } else {
req.isAuthed = false; req.isAuthed = false;
logger.info("auth.middleware: Authentication Failed"); logger.info("auth.middleware: Authentication Failed");
next(); next();
} }
// Handle cases where UUID passed as an array
} else if (Array.isArray(id)) { } else if (Array.isArray(id)) {
const authCheck = (await isAuthed(id[0])) || false; const authCheck = (await isAuthed(id[0])) || false;
if (authCheck) { if (authCheck) {
req.isAuthed = true; req.isAuthed = true;
logger.warn(
"auth.middleware: UUID Passed as Array - Authentication Successful"
);
next(); next();
} else { } else {
req.isAuthed = false; req.isAuthed = false;

View File

@ -141,6 +141,7 @@ async function staffApiCallRetry(api, method, options, retries) {
logger.warn(err, "DNS ERR") logger.warn(err, "DNS ERR")
if (i < retries - 1) { if (i < retries - 1) {
logger.debug('Retrying API Call') logger.debug('Retrying API Call')
await delay(500)
continue; continue;
} }
} }
@ -150,6 +151,10 @@ async function staffApiCallRetry(api, method, options, retries) {
throw new Error("Max retries exceeded"); throw new Error("Max retries exceeded");
} }
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function getReasonCodeList() { async function getReasonCodeList() {
logger.debug("ldbService.getReasonCodeList: Fetching reason code list"); logger.debug("ldbService.getReasonCodeList: Fetching reason code list");
try { try {