nestjs-docfy 0.3.4 → 0.3.6

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.
@@ -35,13 +35,12 @@ export interface DocfyUiSetupOptions {
35
35
  * the same role `SwaggerModule.setup()` + `swagger-ui-express` play for
36
36
  * raw Swagger UI, but for `docfy-ui`.
37
37
  *
38
- * Caveat: `docfy-ui` currently renders with React Router's `BrowserRouter`
39
- * and no configurable `basename`, so deep client-side routes (e.g.
40
- * reloading `/users/findAllUsers` directly) only resolve correctly when
41
- * `mountPath` is `/` — the application's root. Mounting elsewhere (e.g.
42
- * `/docs`) still serves the UI and its initial load works, but in-app
43
- * navigation/reload at a non-root path is not yet supported by `docfy-ui`
44
- * itself.
38
+ * Deep client-side routes (e.g. reloading `/docs/users/findAllUsers`
39
+ * directly) resolve correctly at any `mountPath`: this injects a `<base>`
40
+ * tag matching `mountPath` (so the build's relative asset URLs resolve
41
+ * against it instead of the current, possibly-deep, pathname) and a
42
+ * `window.__DOCFY_BASE_PATH__` global that `docfy-ui` reads to set
43
+ * `BrowserRouter`'s `basename`.
45
44
  */
46
45
  export declare class DocfyUiModule {
47
46
  static setup(mountPath: string, app: DocfyUiSetupTarget, options?: DocfyUiSetupOptions): void;
@@ -43,13 +43,12 @@ const express = __importStar(require("express"));
43
43
  * the same role `SwaggerModule.setup()` + `swagger-ui-express` play for
44
44
  * raw Swagger UI, but for `docfy-ui`.
45
45
  *
46
- * Caveat: `docfy-ui` currently renders with React Router's `BrowserRouter`
47
- * and no configurable `basename`, so deep client-side routes (e.g.
48
- * reloading `/users/findAllUsers` directly) only resolve correctly when
49
- * `mountPath` is `/` — the application's root. Mounting elsewhere (e.g.
50
- * `/docs`) still serves the UI and its initial load works, but in-app
51
- * navigation/reload at a non-root path is not yet supported by `docfy-ui`
52
- * itself.
46
+ * Deep client-side routes (e.g. reloading `/docs/users/findAllUsers`
47
+ * directly) resolve correctly at any `mountPath`: this injects a `<base>`
48
+ * tag matching `mountPath` (so the build's relative asset URLs resolve
49
+ * against it instead of the current, possibly-deep, pathname) and a
50
+ * `window.__DOCFY_BASE_PATH__` global that `docfy-ui` reads to set
51
+ * `BrowserRouter`'s `basename`.
53
52
  */
54
53
  class DocfyUiModule {
55
54
  static setup(mountPath, app, options = {}) {
@@ -62,9 +61,17 @@ class DocfyUiModule {
62
61
  }
63
62
  const indexHtmlPath = require.resolve('docfy-ui/dist/index.html');
64
63
  const uiDir = path.dirname(indexHtmlPath);
65
- app.use(mountPath, express.static(uiDir));
64
+ const basePath = mountPath === '/' ? '/' : `${mountPath.replace(/\/+$/, '')}/`;
65
+ const indexHtml = fs
66
+ .readFileSync(indexHtmlPath, 'utf8')
67
+ .replace('<head>', `<head>\n <base href="${basePath}" />\n <script>window.__DOCFY_BASE_PATH__ = ${JSON.stringify(basePath)};</script>`);
68
+ // `index: false` so directory requests (e.g. `GET /docs/`) fall through
69
+ // to the catch-all below instead of express.static serving the
70
+ // un-patched index.html straight off disk.
71
+ app.use(mountPath, express.static(uiDir, { index: false }));
66
72
  app.use(mountPath, (_req, res) => {
67
- res.sendFile(path.join(uiDir, 'index.html'));
73
+ res.setHeader('Content-Type', 'text/html');
74
+ res.end(indexHtml);
68
75
  });
69
76
  }
70
77
  }
@@ -1 +1 @@
1
- {"version":3,"file":"docfy-ui.module.js","sourceRoot":"","sources":["../src/docfy-ui.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAC7B,iDAAmC;AAmCnC;;;;;;;;;;;;;GAaG;AACH,MAAa,aAAa;IACxB,MAAM,CAAC,KAAK,CACV,SAAiB,EACjB,GAAuB,EACvB,UAA+B,EAAE;QAEjC,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;YAC3B,MAAM,QAAQ,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;YACjE,GAAG,C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gBAClD,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACpB,CAAC,CAAC,CAAC;QACL,CAAC;QAED,MAAM,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC;QAClE,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAC1C,MAAM,QAAQ,GAAG,SAAS,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC;QAC/E,MAAM,SAAS,GAAG,EAAE;aACjB,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC;aACnC,OAAO,CACN,QAAQ,EACR,2BAA2B,QAAQ,kDAAkD,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,YAAY,CAC1H,CAAC;QAEJ,wEAAwE;QACxE,+DAA+D;QAC/D,2CAA2C;QAC3C,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;QAC5D,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,IAAqB,EAAE,GAAqB,EAAE,EAAE;YAClE,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;YAC3C,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAjCD,sCAiCC"}
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "nestjs-docfy",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "description": "Keep your NestJS controllers clean — Swagger docs live in a separate companion file by naming convention",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
+ "types": "./dist/index.d.ts",
9
10
  "require": "./dist/index.js",
10
- "types": "./dist/index.d.ts"
11
+ "default": "./dist/index.js"
11
12
  },
12
13
  "./testing": {
14
+ "types": "./dist/testing.d.ts",
13
15
  "require": "./dist/testing.js",
14
- "types": "./dist/testing.d.ts"
16
+ "default": "./dist/testing.js"
15
17
  }
16
18
  },
17
19
  "bin": {
@@ -85,7 +87,7 @@
85
87
  },
86
88
  "dependencies": {
87
89
  "commander": "^15.0.0",
88
- "docfy-ui": "^0.0.4",
90
+ "docfy-ui": "^0.0.5",
89
91
  "express": "^5.0.0",
90
92
  "picocolors": "^1.1.1",
91
93
  "source-map": "^0.6.1",