shokupan 0.10.2 → 0.10.3

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
@@ -33,10 +33,10 @@ const api = require("@opentelemetry/api");
33
33
  const jsYaml = require("js-yaml");
34
34
  const node_async_hooks = require("node:async_hooks");
35
35
  const os = require("node:os");
36
- const renderToString = require("preact-render-to-string");
37
- const jsxRuntime = require("preact/jsx-runtime");
38
36
  const path$1 = require("node:path");
39
37
  const node_url = require("node:url");
38
+ const renderToString = require("preact-render-to-string");
39
+ const jsxRuntime = require("preact/jsx-runtime");
40
40
  const cluster = require("node:cluster");
41
41
  const net = require("node:net");
42
42
  const node_perf_hooks = require("node:perf_hooks");
@@ -3795,12 +3795,28 @@ function MainContent$1({ allRoutes, config, spec }) {
3795
3795
  ] });
3796
3796
  }
3797
3797
  class ApiExplorerPlugin extends ShokupanRouter {
3798
- constructor(pluginOptions) {
3798
+ constructor(pluginOptions = {}) {
3799
3799
  super({ renderer: renderToString });
3800
3800
  this.pluginOptions = pluginOptions;
3801
3801
  pluginOptions.path ??= "/explorer";
3802
+ }
3803
+ onInit(app, options) {
3804
+ const path2 = this.pluginOptions.path || options?.path || "/apiexplorer";
3805
+ app.mount(path2, this);
3806
+ if (app.applicationConfig.enableOpenApiGen !== true) {
3807
+ console.warn("ApiExplorerPlugin: enableOpenApiGen is disabled. ApiExplorerPlugin will not generate spec.");
3808
+ }
3809
+ }
3810
+ static getBasePath() {
3811
+ const dir = path$1.dirname(node_url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index.cjs", document.baseURI).href));
3812
+ if (dir.endsWith("dist")) {
3813
+ return dir + "/plugins/application/api-explorer";
3814
+ }
3815
+ return dir;
3816
+ }
3817
+ init() {
3802
3818
  const serveFile = async (ctx, file, type) => {
3803
- const content = await promises$1.readFile(path.join(__dirname, "static", file), "utf-8");
3819
+ const content = await promises$1.readFile(path$1.join(ApiExplorerPlugin.getBasePath(), "static", file), "utf-8");
3804
3820
  ctx.set("Content-Type", type);
3805
3821
  return ctx.send(content);
3806
3822
  };