mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-03 21:03:08 +00:00
refactoring the api endpoints to be separate files to reduce context usage
This commit is contained in:
14
apps/server/src/routes/health/common.ts
Normal file
14
apps/server/src/routes/health/common.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Common utilities for health routes
|
||||
*/
|
||||
|
||||
import { createLogger } from "../../lib/logger.js";
|
||||
|
||||
const logger = createLogger("Health");
|
||||
|
||||
/**
|
||||
* Get error message from error object
|
||||
*/
|
||||
export function getErrorMessage(error: unknown): string {
|
||||
return error instanceof Error ? error.message : "Unknown error";
|
||||
}
|
||||
16
apps/server/src/routes/health/index.ts
Normal file
16
apps/server/src/routes/health/index.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Health check routes
|
||||
*/
|
||||
|
||||
import { Router } from "express";
|
||||
import { createIndexHandler } from "./routes/index.js";
|
||||
import { createDetailedHandler } from "./routes/detailed.js";
|
||||
|
||||
export function createHealthRoutes(): Router {
|
||||
const router = Router();
|
||||
|
||||
router.get("/", createIndexHandler());
|
||||
router.get("/detailed", createDetailedHandler());
|
||||
|
||||
return router;
|
||||
}
|
||||
25
apps/server/src/routes/health/routes/detailed.ts
Normal file
25
apps/server/src/routes/health/routes/detailed.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* GET /detailed endpoint - Detailed health check
|
||||
*/
|
||||
|
||||
import type { Request, Response } from "express";
|
||||
import { getAuthStatus } from "../../../lib/auth.js";
|
||||
|
||||
export function createDetailedHandler() {
|
||||
return (_req: Request, res: Response): void => {
|
||||
res.json({
|
||||
status: "ok",
|
||||
timestamp: new Date().toISOString(),
|
||||
version: process.env.npm_package_version || "0.1.0",
|
||||
uptime: process.uptime(),
|
||||
memory: process.memoryUsage(),
|
||||
dataDir: process.env.DATA_DIR || "./data",
|
||||
auth: getAuthStatus(),
|
||||
env: {
|
||||
nodeVersion: process.version,
|
||||
platform: process.platform,
|
||||
arch: process.arch,
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
15
apps/server/src/routes/health/routes/index.ts
Normal file
15
apps/server/src/routes/health/routes/index.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* GET / endpoint - Basic health check
|
||||
*/
|
||||
|
||||
import type { Request, Response } from "express";
|
||||
|
||||
export function createIndexHandler() {
|
||||
return (_req: Request, res: Response): void => {
|
||||
res.json({
|
||||
status: "ok",
|
||||
timestamp: new Date().toISOString(),
|
||||
version: process.env.npm_package_version || "0.1.0",
|
||||
});
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user