Refactor transit_api into a repo/routes module split
Split the 5,441-line index.js into an 86-line bootstrap, thin domain
route modules, shared lib/ helpers, and a repo/ layer that isolates the
DEV_MOCK branches (repo/*.mock.js). Repo methods return {statusCode, body};
routes are one-line wrappers. Pin search_path to "transit.bus" and
document the /bus/ prefix with legacy root aliases (Deprecation header).
Parity verified: 57/57 byte-identical on the stub differential harness
plus 24/24 live read-only responses vs the original against real
PostgreSQL. The only intentional behavior change: mock reorder/delete
bus-line endpoints no longer require a live DB (previously 500 in
DEV_MOCK=1 without PG). DEV_MOCK gate and node --check clean.
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const db = require("../db");
|
||||
const { log } = require("../lib/log");
|
||||
const { reportError } = require("../lib/report-error");
|
||||
|
||||
router.get("/", async (_req, res) => {
|
||||
try {
|
||||
await db.query("SELECT 1");
|
||||
res.json({ status: "ok", service: "transit_api", database: "ok" });
|
||||
} catch (err) {
|
||||
log("error", "GET /health error", { error: err.message, stack: err.stack });
|
||||
reportError({ partofservice: "GET /health", error: err.stack || err.message });
|
||||
res.status(503).json({ status: "unavailable", service: "transit_api" });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user