Merge pull request #353 from mchangrh/statusOptions

get status with options
This commit is contained in:
Ajay Ramachandran
2021-09-02 12:04:38 -04:00
committed by GitHub
3 changed files with 68 additions and 4 deletions

View File

@@ -3,14 +3,19 @@ import {Logger} from "../utils/logger";
import {Request, Response} from "express";
export async function getStatus(req: Request, res: Response): Promise<Response> {
const startTime = Date.now();
let value = req.params.value as string[] | string;
value = Array.isArray(value) ? value[0] : value;
try {
const dbVersion = (await db.prepare("get", "SELECT key, value FROM config where key = ?", ["version"])).value;
return res.send({
const statusValues: Record<string, any> = {
uptime: process.uptime(),
commit: (global as any).HEADCOMMIT || "unknown",
db: Number(dbVersion),
});
startTime,
processTime: Date.now() - startTime,
};
return value ? res.send(String(statusValues[value])) : res.send(statusValues);
} catch (err) {
Logger.error(err as string);
return res.sendStatus(500);