Skip to content

Commit 22c5880

Browse files
authored
Merge pull request #57 from sirloinbh/chore/standards-sync-90927f0
chore: sync central standards (project-standards@90927f0)
2 parents 8f35afc + df079d2 commit 22c5880

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎.standards/check.mjs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,13 @@ export function checkApi(sources) {
8888
const at = (source, index) => `${source.file}:${source.text.slice(0, index).split('\n').length}`;
8989
if (!sources.some((s) => /\bapp\.get\(\s*['"`]\/api\/health['"`]/.test(s.text))) warnings.push('backend/src: GET /api/health is missing. Every app has a health check API that verifies the DB connection.');
9090
if (!/\bapp\.use\(\s*(errorHandler\b|\(\s*err\b)/.test(app.text)) warnings.push('backend/src/app.ts: the error middleware (app.use(errorHandler)) is missing, so errors are not returned as { error }.');
91-
if (!/\bapp\.use\(\s*requestLog\b/.test(app.text)) warnings.push('backend/src/app.ts: app.use(requestLog) is missing, so requests get no request ID or JSON log line (docs/logging.md).');
91+
const logAt = app.text.search(/\bapp\.use\(\s*requestLog\b/);
92+
if (logAt < 0) warnings.push('backend/src/app.ts: app.use(requestLog) is missing, so requests get no request ID or JSON log line (docs/logging.md).');
93+
else {
94+
// Routes mounted before requestLog get no request ID. The health check may come first (study-log), so it is not counted.
95+
const early = [...app.text.slice(0, logAt).matchAll(/\bapp\.(?:post|put|patch|delete|use)\(\s*['"`]\/(?:api|internal)(?:\/|['"`])/g)];
96+
if (early.length > 0) warnings.push(`${at(app, early[0].index)}: app.use(requestLog) must be mounted before the routes, or they get no request ID or JSON log line (docs/logging.md).`);
97+
}
9298
if (!/\bapp\.use\(\s*['"`]\/api['"`]\s*,/.test(app.text)) warnings.push("backend/src/app.ts: app.use('/api', notFound), which answers unknown /api paths with 404 { error }, is missing.");
9399
for (const source of sources) {
94100
for (const m of source.text.matchAll(/\bapp\.(get|post|put|patch|delete|use)\(\s*['"]([^'"]+)['"]/g)) {

‎.standards/manifest.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"centralSha": "71970fbfc3b70cbd4fe281523d5bb0f88ff9e08b",
2+
"centralSha": "90927f0d12e467d587218467f2da9f404032e2c1",
33
"profile": "infra",
44
"project": null,
55
"files": {
@@ -105,7 +105,7 @@
105105
},
106106
".standards/check.mjs": {
107107
"mode": "full",
108-
"sha256": "ea51c44c412ef5cf2ec0272719287371f4a81472fe4ab32da7ca5d32bfabc208",
108+
"sha256": "fae1d3fa14cdb90a9320ed35e5565a7f382448570b87badf4e7c1e3b6130f8e6",
109109
"source": "scripts/standards-check.mjs"
110110
},
111111
".standards/ioc-scan.mjs": {

0 commit comments

Comments
 (0)