feat: added status route to api

This commit is contained in:
Rushil Umaretiya 2023-03-06 09:34:37 -05:00
parent 4bf903eede
commit a1dfa54681
2 changed files with 31 additions and 8 deletions

20
src/api/status.js Normal file
View File

@ -0,0 +1,20 @@
import { Router } from "express";
import { db } from "../lib/db.js";
const app = Router();
app.get("/", async (req, res) => {
const messageCount = await db.message.count();
const sessionCount = await db.session.count();
const operatorCount = await db.operator.count();
return res.status(200).json({
status: "OK",
time: new Date().toISOString(),
messageCount: messageCount,
sessionCount: sessionCount,
operatorCount: operatorCount,
});
});
export default app;

View File

@ -1,17 +1,20 @@
import express from "express";
import cors from "cors";
import call from "./api/call.js";
import operator from "./api/operator.js"
import session from "./api/session.js"
import cors from "cors"
import operator from "./api/operator.js";
import session from "./api/session.js";
import status from "./api/status.js";
const app = express();
app.use(express.urlencoded({ extended: false }));
app.use(express.json())
app.use(cors())
app.use(express.json());
app.use(cors());
app.use('/call', call)
app.use('/operator', operator)
app.use('/session', session)
app.use("/call", call);
app.use("/operator", operator);
app.use("/session", session);
app.use("/status", status);
// Create an HTTP server and listen for requests on port 3000
app.listen(8080, () => {