flowdoc-gen 0.1.4 → 0.1.5

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/index.cjs CHANGED
@@ -1333,6 +1333,7 @@ var MIME = {
1333
1333
  ".json": "application/json"
1334
1334
  };
1335
1335
  var flowdoc = (opts = {}) => {
1336
+ const disabled = opts.disabled ?? process.env.NODE_ENV === "production";
1336
1337
  const cwd = process.cwd();
1337
1338
  let outputDir = null;
1338
1339
  let ready = false;
@@ -1361,6 +1362,10 @@ var flowdoc = (opts = {}) => {
1361
1362
  }
1362
1363
  })();
1363
1364
  return async (req, res, next) => {
1365
+ if (disabled) {
1366
+ res.status(403).send("API docs are not available in this environment.");
1367
+ return;
1368
+ }
1364
1369
  await init2;
1365
1370
  if (initError || !outputDir) {
1366
1371
  res.status(500).send(`flowdoc init failed: ${initError}`);
@@ -1370,8 +1375,9 @@ var flowdoc = (opts = {}) => {
1370
1375
  if (urlPath === "/index.html") {
1371
1376
  const brand = "#6366f1";
1372
1377
  const baseUrl = `${req.protocol}://${req.get("host")}`;
1378
+ const docsBase = req.baseUrl || "";
1373
1379
  res.setHeader("Content-Type", "text/html");
1374
- res.send(buildHtml({ baseUrl, brand }));
1380
+ res.send(buildHtml({ baseUrl, brand, docsBase }));
1375
1381
  return;
1376
1382
  }
1377
1383
  const filePath = (0, import_path6.join)(outputDir, urlPath);
@@ -1384,7 +1390,7 @@ var flowdoc = (opts = {}) => {
1384
1390
  (0, import_fs6.createReadStream)(filePath).pipe(res);
1385
1391
  };
1386
1392
  };
1387
- var buildHtml = ({ baseUrl, brand }) => `<!DOCTYPE html>
1393
+ var buildHtml = ({ baseUrl, brand, docsBase }) => `<!DOCTYPE html>
1388
1394
  <html lang="en" class="dark">
1389
1395
  <head>
1390
1396
  <meta charset="UTF-8" />
@@ -1393,9 +1399,10 @@ var buildHtml = ({ baseUrl, brand }) => `<!DOCTYPE html>
1393
1399
  <script>
1394
1400
  window.__FLOWDOC_BRAND__ = "${brand}";
1395
1401
  window.__FLOWDOC_BASE_URL__ = "${baseUrl}";
1402
+ window.__FLOWDOC_DOCS_BASE__ = "${docsBase}";
1396
1403
  </script>
1397
- <script type="module" crossorigin src="./assets/ui.js"></script>
1398
- <link rel="stylesheet" href="./assets/index.css" />
1404
+ <script type="module" crossorigin src="${docsBase}/assets/ui.js"></script>
1405
+ <link rel="stylesheet" href="${docsBase}/assets/index.css" />
1399
1406
  </head>
1400
1407
  <body><div id="root"></div></body>
1401
1408
  </html>`;
package/dist/index.d.cts CHANGED
@@ -131,6 +131,13 @@ interface FlowDocMiddlewareOptions {
131
131
  config?: string;
132
132
  /** Route prefix the middleware is mounted at — used only for the HTML shell */
133
133
  path?: string;
134
+ /**
135
+ * Disable the docs endpoint. Useful for production environments.
136
+ * Defaults to `process.env.NODE_ENV === "production"` when not set,
137
+ * meaning docs are served in development and blocked in production.
138
+ * Pass `false` to explicitly enable in production; `true` to always block.
139
+ */
140
+ disabled?: boolean;
134
141
  }
135
142
  /**
136
143
  * Express middleware that serves flowdoc docs at whatever route you mount it on.
package/dist/index.d.ts CHANGED
@@ -131,6 +131,13 @@ interface FlowDocMiddlewareOptions {
131
131
  config?: string;
132
132
  /** Route prefix the middleware is mounted at — used only for the HTML shell */
133
133
  path?: string;
134
+ /**
135
+ * Disable the docs endpoint. Useful for production environments.
136
+ * Defaults to `process.env.NODE_ENV === "production"` when not set,
137
+ * meaning docs are served in development and blocked in production.
138
+ * Pass `false` to explicitly enable in production; `true` to always block.
139
+ */
140
+ disabled?: boolean;
134
141
  }
135
142
  /**
136
143
  * Express middleware that serves flowdoc docs at whatever route you mount it on.
package/dist/index.js CHANGED
@@ -1293,6 +1293,7 @@ var MIME = {
1293
1293
  ".json": "application/json"
1294
1294
  };
1295
1295
  var flowdoc = (opts = {}) => {
1296
+ const disabled = opts.disabled ?? process.env.NODE_ENV === "production";
1296
1297
  const cwd = process.cwd();
1297
1298
  let outputDir = null;
1298
1299
  let ready = false;
@@ -1321,6 +1322,10 @@ var flowdoc = (opts = {}) => {
1321
1322
  }
1322
1323
  })();
1323
1324
  return async (req, res, next) => {
1325
+ if (disabled) {
1326
+ res.status(403).send("API docs are not available in this environment.");
1327
+ return;
1328
+ }
1324
1329
  await init2;
1325
1330
  if (initError || !outputDir) {
1326
1331
  res.status(500).send(`flowdoc init failed: ${initError}`);
@@ -1330,8 +1335,9 @@ var flowdoc = (opts = {}) => {
1330
1335
  if (urlPath === "/index.html") {
1331
1336
  const brand = "#6366f1";
1332
1337
  const baseUrl = `${req.protocol}://${req.get("host")}`;
1338
+ const docsBase = req.baseUrl || "";
1333
1339
  res.setHeader("Content-Type", "text/html");
1334
- res.send(buildHtml({ baseUrl, brand }));
1340
+ res.send(buildHtml({ baseUrl, brand, docsBase }));
1335
1341
  return;
1336
1342
  }
1337
1343
  const filePath = join5(outputDir, urlPath);
@@ -1344,7 +1350,7 @@ var flowdoc = (opts = {}) => {
1344
1350
  createReadStream2(filePath).pipe(res);
1345
1351
  };
1346
1352
  };
1347
- var buildHtml = ({ baseUrl, brand }) => `<!DOCTYPE html>
1353
+ var buildHtml = ({ baseUrl, brand, docsBase }) => `<!DOCTYPE html>
1348
1354
  <html lang="en" class="dark">
1349
1355
  <head>
1350
1356
  <meta charset="UTF-8" />
@@ -1353,9 +1359,10 @@ var buildHtml = ({ baseUrl, brand }) => `<!DOCTYPE html>
1353
1359
  <script>
1354
1360
  window.__FLOWDOC_BRAND__ = "${brand}";
1355
1361
  window.__FLOWDOC_BASE_URL__ = "${baseUrl}";
1362
+ window.__FLOWDOC_DOCS_BASE__ = "${docsBase}";
1356
1363
  </script>
1357
- <script type="module" crossorigin src="./assets/ui.js"></script>
1358
- <link rel="stylesheet" href="./assets/index.css" />
1364
+ <script type="module" crossorigin src="${docsBase}/assets/ui.js"></script>
1365
+ <link rel="stylesheet" href="${docsBase}/assets/index.css" />
1359
1366
  </head>
1360
1367
  <body><div id="root"></div></body>
1361
1368
  </html>`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flowdoc-gen",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Auto-generate beautiful API documentation from your Express codebase — no annotations required",
5
5
  "type": "module",
6
6
  "bin": {