import { auth, readPM2Logs } from "@log/pm2-viewer";
import userRouter from "./user.routes";
import { LOG } from "@log/index";
export const routeLoader = (app) => {
app.use("/user", userRouter)
app.get("/ping", (req, res) => {
res.send("ping routes working responding pong");
})
app.get("/pm2/logs", auth, readPM2Logs);
app.get("*", function (req, res) {
return res.errorResponse(404, "Route not found", {})
});
app.use((err, req, res, next) => {
LOG.error(err.message || "Internal Server Error", err);
const statusCode = err.statusCode || 500
const errorMessage = err.message || "Internal Server Error";
return res.status(statusCode).json({
status: false,
status_code: statusCode,
message: errorMessage,
data: {},
});
})
return app
}