hasancode-api-docs 1.0.15 → 1.0.17

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.
@@ -2,7 +2,7 @@
2
2
  <html lang="en">
3
3
  <head>
4
4
  <meta charset="UTF-8" />
5
- <link rel="icon" type="image/svg+xml" href="./logo.png" />
5
+ <link rel="icon" type="image/svg+xml" href="/api-docs/logo.png" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
 
8
8
  <link rel="preconnect" href="https://fonts.googleapis.com" />
@@ -13,9 +13,9 @@
13
13
  />
14
14
 
15
15
  <title>API Doc</title>
16
- <script type="module" crossorigin src="./assets/index-DA78l2zr.js"></script>
17
- <link rel="modulepreload" crossorigin href="./assets/vendor-Cy83rCXF.js">
18
- <link rel="stylesheet" crossorigin href="./assets/index-BddYm5rR.css">
16
+ <script type="module" crossorigin src="/api-docs/assets/index-CAGuZ--I.js"></script>
17
+ <link rel="modulepreload" crossorigin href="/api-docs/assets/vendor-r6CGHiWc.js">
18
+ <link rel="stylesheet" crossorigin href="/api-docs/assets/index-BddYm5rR.css">
19
19
  </head>
20
20
  <body>
21
21
  <div id="root"></div>
@@ -78,7 +78,6 @@ class ApiDoc {
78
78
  path.join(__dirname, "../../client/dist"),
79
79
  path.join(__dirname, "../client/dist"),
80
80
  path.join(__dirname, "../../../client/dist"),
81
- // Fallback for some npm structures
82
81
  path.join(process.cwd(), "node_modules/hasancode-api-docs/client/dist"),
83
82
  ];
84
83
  for (const testPath of possiblePaths) {
@@ -202,25 +201,20 @@ class ApiDoc {
202
201
  */
203
202
  middleware() {
204
203
  const router = (0, express_1.Router)();
205
- // 1. Serve config.json
206
- router.get(`${this.DOCS_PATH}/config.json`, this.serveConfig.bind(this));
207
- // 3. Serve static assets with explicit MIME types
208
- router.use(`${this.DOCS_PATH}/assets`, (req, res, next) => {
209
- const ext = path.extname(req.path).toLowerCase();
210
- if (ext === ".js") {
211
- res.setHeader("Content-Type", "application/javascript; charset=utf-8");
212
- }
213
- else if (ext === ".css") {
214
- res.setHeader("Content-Type", "text/css; charset=utf-8");
215
- }
216
- next();
217
- }, (0, express_1.static)(path.join(this.clientPath, "assets"), {
204
+ router.use(`${this.DOCS_PATH}/assets`, (0, express_1.static)(path.join(this.clientPath, "assets"), {
218
205
  maxAge: "1d",
219
206
  etag: true,
220
- index: false,
221
207
  fallthrough: false,
208
+ setHeaders: (res, path) => {
209
+ if (path.endsWith(".js")) {
210
+ res.setHeader("Content-Type", "application/javascript");
211
+ }
212
+ else if (path.endsWith(".css")) {
213
+ res.setHeader("Content-Type", "text/css");
214
+ }
215
+ },
222
216
  }));
223
- // 4. Serve the React app
217
+ router.get(`${this.DOCS_PATH}/config.json`, this.serveConfig.bind(this));
224
218
  router.use(this.serveApp.bind(this));
225
219
  return router;
226
220
  }
@@ -247,54 +241,48 @@ class ApiDoc {
247
241
  const indexPath = path.join(this.clientPath, "index.html");
248
242
  if (fs.existsSync(indexPath)) {
249
243
  let html = fs.readFileSync(indexPath, "utf-8");
250
- // Calculate the absolute base path for the documentation
251
- // This makes the app portable even when mounted at a prefix
252
- const mountPath = req.baseUrl || "";
253
- const docsPath = this.DOCS_PATH.startsWith("/")
254
- ? this.DOCS_PATH
255
- : `/${this.DOCS_PATH}`;
256
- const fullPath = (mountPath + docsPath).replace(/\/+$/, "");
257
- const baseTag = `<base href="${fullPath}/">`;
258
- // Insert or replace base tag
259
- if (html.includes("<base ")) {
244
+ // Inject base tag with trailing slash for proper asset resolution
245
+ const baseTag = `<base href="${this.DOCS_PATH}/">`;
246
+ // Insert base tag right after <head> or before any other tags
247
+ if (html.includes("<base")) {
248
+ // Replace existing base tag
260
249
  html = html.replace(/<base[^>]*>/i, baseTag);
261
250
  }
262
251
  else {
252
+ // Insert new base tag
263
253
  html = html.replace(/<head>/i, `<head>${baseTag}`);
264
254
  }
265
- // Also ensure any absolute references in index.html are corrected
266
- html = html.replace(/\/api-docs\/assets\//g, "assets/");
267
- res.setHeader("Content-Type", "text/html; charset=utf-8");
255
+ res.setHeader("Content-Type", "text/html");
268
256
  res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
269
257
  res.send(html);
270
258
  }
271
259
  else {
272
260
  res.status(404).send(`
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>
261
+ <html>
262
+ <head>
263
+ <title>API Docs - Not Built</title>
264
+ <style>
265
+ body {
266
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
267
+ max-width: 600px;
268
+ margin: 100px auto;
269
+ padding: 20px;
270
+ text-align: center;
271
+ }
272
+ h1 { color: #e53e3e; }
273
+ code {
274
+ background: #f7fafc;
275
+ padding: 2px 6px;
276
+ border-radius: 4px;
277
+ }
278
+ </style>
279
+ </head>
280
+ <body>
281
+ <h1>⚠️ Client Not Built</h1>
282
+ <p>Please run <code>npm run build</code> first.</p>
283
+ <p><small>Looking at: ${this.clientPath}</small></p>
284
+ </body>
285
+ </html>
298
286
  `);
299
287
  }
300
288
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hasancode-api-docs",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
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",