hasancode-api-docs 1.0.13 → 1.0.14

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.
@@ -250,9 +250,11 @@ 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("/") ? this.DOCS_PATH : `/${this.DOCS_PATH}`;
253
+ const docsPath = this.DOCS_PATH.startsWith("/")
254
+ ? this.DOCS_PATH
255
+ : `/${this.DOCS_PATH}`;
254
256
  const fullPath = (mountPath + docsPath).replace(/\/+$/, "");
255
- const baseTag = `<base href="${fullPath}/">`;
257
+ const baseTag = `<base href="${fullPath}">`;
256
258
  // Insert or replace base tag
257
259
  if (html.includes("<base ")) {
258
260
  html = html.replace(/<base[^>]*>/i, baseTag);
@@ -268,32 +270,32 @@ class ApiDoc {
268
270
  }
269
271
  else {
270
272
  res.status(404).send(`
271
- <html>
272
- <head>
273
- <title>API Docs - Not Built</title>
274
- <style>
275
- body {
276
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
277
- max-width: 600px;
278
- margin: 100px auto;
279
- padding: 20px;
280
- text-align: center;
281
- }
282
- h1 { color: #e53e3e; }
283
- code {
284
- background: #f7fafc;
285
- padding: 2px 6px;
286
- border-radius: 4px;
287
- }
288
- </style>
289
- </head>
290
- <body>
291
- <h1>⚠️ Client Not Built</h1>
292
- <p>Please run <code>npm run build</code> first.</p>
293
- <p><small>Looking at: ${this.clientPath}</small></p>
294
- </body>
295
- </html>
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,6 +1,6 @@
1
1
  {
2
2
  "name": "hasancode-api-docs",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "A simple and easy to use API documentation generator for Express.js",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -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
- }