hasancode-api-docs 1.0.13 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/middleware/ApiDoc.js +29 -27
- package/package.json +1 -1
- package/dist/middleware/RouteDoc.js +0 -47
|
@@ -250,7 +250,9 @@ class ApiDoc {
|
|
|
250
250
|
// Calculate the absolute base path for the documentation
|
|
251
251
|
// This makes the app portable even when mounted at a prefix
|
|
252
252
|
const mountPath = req.baseUrl || "";
|
|
253
|
-
const docsPath = this.DOCS_PATH.startsWith("/")
|
|
253
|
+
const docsPath = this.DOCS_PATH.startsWith("/")
|
|
254
|
+
? this.DOCS_PATH
|
|
255
|
+
: `/${this.DOCS_PATH}`;
|
|
254
256
|
const fullPath = (mountPath + docsPath).replace(/\/+$/, "");
|
|
255
257
|
const baseTag = `<base href="${fullPath}/">`;
|
|
256
258
|
// Insert or replace base tag
|
|
@@ -268,32 +270,32 @@ class ApiDoc {
|
|
|
268
270
|
}
|
|
269
271
|
else {
|
|
270
272
|
res.status(404).send(`
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
273
|
+
<html>
|
|
274
|
+
<head>
|
|
275
|
+
<title>API Docs - Not Built</title>
|
|
276
|
+
<style>
|
|
277
|
+
body {
|
|
278
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
279
|
+
max-width: 600px;
|
|
280
|
+
margin: 100px auto;
|
|
281
|
+
padding: 20px;
|
|
282
|
+
text-align: center;
|
|
283
|
+
}
|
|
284
|
+
h1 { color: #e53e3e; }
|
|
285
|
+
code {
|
|
286
|
+
background: #f7fafc;
|
|
287
|
+
padding: 2px 6px;
|
|
288
|
+
border-radius: 4px;
|
|
289
|
+
}
|
|
290
|
+
</style>
|
|
291
|
+
</head>
|
|
292
|
+
<body>
|
|
293
|
+
<h1>⚠️ Client Not Built</h1>
|
|
294
|
+
<p>Please run <code>npm run build</code> first.</p>
|
|
295
|
+
<p><small>Looking at: ${this.clientPath}</small></p>
|
|
296
|
+
</body>
|
|
297
|
+
</html>
|
|
298
|
+
`);
|
|
297
299
|
}
|
|
298
300
|
}
|
|
299
301
|
/**
|
package/package.json
CHANGED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.doc = doc;
|
|
4
|
-
const RouteRegistry_1 = require("../registry/RouteRegistry");
|
|
5
|
-
/**
|
|
6
|
-
* doc() — Express route middleware that registers API documentation.
|
|
7
|
-
*
|
|
8
|
-
* Two signatures:
|
|
9
|
-
*
|
|
10
|
-
* ① As a standalone middleware — method & path come from Express router:
|
|
11
|
-
*
|
|
12
|
-
* router.post('/users', doc({ summary: 'Create user', ... }), handler);
|
|
13
|
-
*
|
|
14
|
-
* ② Wrapping the handler directly (handler runs after doc is registered):
|
|
15
|
-
*
|
|
16
|
-
* router.post('/signin/:userType',
|
|
17
|
-
* validateRequest(schema),
|
|
18
|
-
* doc({ summary: 'Sign in', tags: ['Auth'], ... }, AuthControllers.signin),
|
|
19
|
-
* );
|
|
20
|
-
*/
|
|
21
|
-
function doc(options, handler) {
|
|
22
|
-
let registered = false; // register once per route, not on every request
|
|
23
|
-
const middleware = (req, res, next) => {
|
|
24
|
-
var _a, _b, _c, _d;
|
|
25
|
-
if (!registered) {
|
|
26
|
-
registered = true;
|
|
27
|
-
// Express populates req.route only once the route is matched
|
|
28
|
-
// (i.e. on the first real request). We use that to get method & path.
|
|
29
|
-
const method = ((_b = (_a = req.method) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : "get");
|
|
30
|
-
// req.route.path gives us the pattern (/users/:id),
|
|
31
|
-
// NOT the actual URL — exactly what we want for docs.
|
|
32
|
-
const path = (_d = (_c = req.route) === null || _c === void 0 ? void 0 : _c.path) !== null && _d !== void 0 ? _d : req.path;
|
|
33
|
-
const routeDoc = Object.assign({ method,
|
|
34
|
-
path }, options);
|
|
35
|
-
console.log(routeDoc);
|
|
36
|
-
RouteRegistry_1.routeRegistry.register(routeDoc);
|
|
37
|
-
}
|
|
38
|
-
// If the user passed a handler as second arg, call it directly
|
|
39
|
-
if (handler) {
|
|
40
|
-
return handler(req, res, next);
|
|
41
|
-
}
|
|
42
|
-
next();
|
|
43
|
-
};
|
|
44
|
-
// Mark this middleware so ApiDoc can identify it if needed
|
|
45
|
-
middleware.__isDocMiddleware = true;
|
|
46
|
-
return middleware;
|
|
47
|
-
}
|