hasancode-api-docs 1.0.10 → 1.0.11

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.
@@ -202,9 +202,14 @@ class ApiDoc {
202
202
  */
203
203
  middleware() {
204
204
  const router = (0, express_1.Router)();
205
- // 1. Serve config.json
205
+ // 1. Handle trailing slash redirect for the root path
206
+ // This is crucial for relative asset resolution
207
+ router.get(this.DOCS_PATH, (req, res) => {
208
+ res.redirect(301, req.originalUrl + "/");
209
+ });
210
+ // 2. Serve config.json
206
211
  router.get(`${this.DOCS_PATH}/config.json`, this.serveConfig.bind(this));
207
- // 2. Serve static assets with explicit MIME types
212
+ // 3. Serve static assets with explicit MIME types
208
213
  router.use(`${this.DOCS_PATH}/assets`, (req, res, next) => {
209
214
  const ext = path.extname(req.path).toLowerCase();
210
215
  if (ext === ".js") {
@@ -220,7 +225,7 @@ class ApiDoc {
220
225
  index: false,
221
226
  fallthrough: false,
222
227
  }));
223
- // 3. Serve the React app
228
+ // 4. Serve the React app
224
229
  router.use(this.serveApp.bind(this));
225
230
  return router;
226
231
  }
@@ -247,7 +252,8 @@ class ApiDoc {
247
252
  const indexPath = path.join(this.clientPath, "index.html");
248
253
  if (fs.existsSync(indexPath)) {
249
254
  let html = fs.readFileSync(indexPath, "utf-8");
250
- // Use relative base tag so it works when mounted at any prefix
255
+ // Inject base tag with trailing slash for proper asset resolution
256
+ // We use relative './' which depends on the URL ending with a slash
251
257
  const baseTag = `<base href="./">`;
252
258
  // Insert or replace base tag
253
259
  if (html.includes("<base ")) {
@@ -256,6 +262,8 @@ class ApiDoc {
256
262
  else {
257
263
  html = html.replace(/<head>/i, `<head>${baseTag}`);
258
264
  }
265
+ // Also ensure any absolute references in index.html are corrected if they slipped through
266
+ html = html.replace(/\/api-docs\/assets\//g, "assets/");
259
267
  res.setHeader("Content-Type", "text/html; charset=utf-8");
260
268
  res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
261
269
  res.send(html);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hasancode-api-docs",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
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",