@scalar/fastify-api-reference 0.7.1 → 0.7.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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @scalar/fastify-api-reference
2
2
 
3
+ ## 0.7.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 2bfab93: fix: JS is missing
8
+
9
+ ## 0.7.2
10
+
11
+ ### Patch Changes
12
+
13
+ - 185a85d: breaking change: use `configuration` instead of `apiReference` to pass the configuration
14
+ - 185a85d: refactor: use CDN version, remove pageTitle option (the API reference supports more attributes already)
15
+ - Updated dependencies [37b974c]
16
+ - Updated dependencies [b77d087]
17
+ - @scalar/api-reference@1.3.0
18
+
3
19
  ## 0.7.1
4
20
 
5
21
  ### Patch Changes
package/README.md CHANGED
@@ -31,7 +31,7 @@ If you have a OpenAPI/Swagger file already, you can pass an URL to the plugin:
31
31
  // Render an API reference for a given OpenAPI/Swagger spec URL
32
32
  fastify.register(require('@scalar/fastify-api-reference'), {
33
33
  routePrefix: '/reference',
34
- apiReference: {
34
+ configuration: {
35
35
  title: 'Our API Reference',
36
36
  spec: {
37
37
  url: '/swagger.json',
@@ -45,7 +45,7 @@ With the [@fastify/swagger](https://github.com/fastify/fastify-swagger) you can
45
45
  ```ts
46
46
  await fastify.register(require('@scalar/fastify-api-reference'), {
47
47
  routePrefix: '/reference',
48
- apiReference: {
48
+ configuration: {
49
49
  spec: {
50
50
  content: () => fastify.swagger(),
51
51
  },
@@ -66,7 +66,7 @@ Or, if you just have a static OpenAPI spec, you can directly pass it, too:
66
66
  ```ts
67
67
  await fastify.register(require('@scalar/fastify-api-reference'), {
68
68
  routePrefix: '/reference',
69
- apiReference: {
69
+ configuration: {
70
70
  spec: {
71
71
  content: { … }
72
72
  },
@@ -83,7 +83,7 @@ By default, we’re using a custom Fastify theme and it’s beautiful. But you c
83
83
  ```ts
84
84
  await fastify.register(require('@scalar/fastify-api-reference'), {
85
85
  routePrefix: '/reference',
86
- apiReference: {
86
+ configuration: {
87
87
  theme: 'purple',
88
88
  },
89
89
  })
@@ -1,16 +1,26 @@
1
1
  import { type ReferenceConfiguration } from '@scalar/api-reference';
2
2
  import type { FastifyPluginAsync } from 'fastify';
3
- export type ApiReferenceOptions = {
3
+ export type FastifyApiReferenceOptions = {
4
4
  /**
5
5
  * Prefix for the registered route
6
6
  *
7
7
  * @default '/'
8
8
  */
9
9
  routePrefix: string;
10
- apiReference?: ReferenceConfiguration & {
11
- pageTitle?: string;
12
- };
10
+ configuration?: ReferenceConfiguration;
13
11
  };
14
- declare const _default: FastifyPluginAsync<ApiReferenceOptions>;
12
+ /**
13
+ * The Fastify custom theme CSS
14
+ */
15
+ export declare const defaultCss = "\n:root {\n --theme-font: 'Inter', var(--system-fonts);\n}\n\n.light-mode {\n color-scheme: light;\n --theme-color-1: #1c1e21;\n --theme-color-2: #757575;\n --theme-color-3: #8e8e8e;\n --theme-color-disabled: #b4b1b1;\n --theme-color-ghost: #a7a7a7;\n --theme-color-accent: #2f8555;\n --theme-background-1: #fff;\n --theme-background-2: #f5f5f5;\n --theme-background-3: #ededed;\n --theme-background-4: rgba(0, 0, 0, 0.06);\n --theme-background-accent: #2f85551f;\n\n --theme-border-color: rgba(0, 0, 0, 0.1);\n --theme-scrollbar-color: rgba(0, 0, 0, 0.18);\n --theme-scrollbar-color-active: rgba(0, 0, 0, 0.36);\n --theme-lifted-brightness: 1;\n --theme-backdrop-brightness: 1;\n\n --theme-shadow-1: 0 1px 3px 0 rgba(0, 0, 0, 0.11);\n --theme-shadow-2: rgba(0, 0, 0, 0.08) 0px 13px 20px 0px,\n rgba(0, 0, 0, 0.08) 0px 3px 8px 0px, #eeeeed 0px 0 0 1px;\n\n --theme-button-1: rgb(49 53 56);\n --theme-button-1-color: #fff;\n --theme-button-1-hover: rgb(28 31 33);\n\n --theme-color-green: #007300;\n --theme-color-red: #af272b;\n --theme-color-yellow: #b38200;\n --theme-color-blue: #3b8ba5;\n --theme-color-orange: #fb892c;\n --theme-color-purple: #5203d1;\n}\n\n.dark-mode {\n color-scheme: dark;\n --theme-color-1: rgba(255, 255, 255, 0.9);\n --theme-color-2: rgba(255, 255, 255, 0.62);\n --theme-color-3: rgba(255, 255, 255, 0.44);\n --theme-color-disabled: rgba(255, 255, 255, 0.34);\n --theme-color-ghost: rgba(255, 255, 255, 0.26);\n --theme-color-accent: #27c2a0;\n --theme-background-1: #1b1b1d;\n --theme-background-2: #242526;\n --theme-background-3: #3b3b3b;\n --theme-background-4: rgba(255, 255, 255, 0.06);\n --theme-background-accent: #27c2a01f;\n\n --theme-border-color: rgba(255, 255, 255, 0.1);\n --theme-scrollbar-color: rgba(255, 255, 255, 0.24);\n --theme-scrollbar-color-active: rgba(255, 255, 255, 0.48);\n --theme-lifted-brightness: 1.45;\n --theme-backdrop-brightness: 0.5;\n\n --theme-shadow-1: 0 1px 3px 0 rgb(0, 0, 0, 0.1);\n --theme-shadow-2: rgba(15, 15, 15, 0.2) 0px 3px 6px,\n rgba(15, 15, 15, 0.4) 0px 9px 24px, 0 0 0 1px rgba(255, 255, 255, 0.1);\n\n --theme-button-1: #f6f6f6;\n --theme-button-1-color: #000;\n --theme-button-1-hover: #e7e7e7;\n\n --theme-color-green: #26b226;\n --theme-color-red: #fb565b;\n --theme-color-yellow: #ffc426;\n --theme-color-blue: #6ecfef;\n --theme-color-orange: #ff8d4d;\n --theme-color-purple: #b191f9;\n}\n.scalar-card:nth-of-type(3) {\n display: none;\n}\n";
16
+ /**
17
+ * The HTML to load the @scalar/api-reference JavaScript package.
18
+ */
19
+ export declare const javascript: (configuration: ReferenceConfiguration) => string;
20
+ /**
21
+ * The HTML template to render the API Reference.
22
+ */
23
+ export declare function htmlDocument(configuration: ReferenceConfiguration): string;
24
+ declare const _default: FastifyPluginAsync<FastifyApiReferenceOptions>;
15
25
  export default _default;
16
26
  //# sourceMappingURL=fastifyApiReference.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fastifyApiReference.d.ts","sourceRoot":"","sources":["../src/fastifyApiReference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAEnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAKjD,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,sBAAsB,GAAG;QACtC,SAAS,CAAC,EAAE,MAAM,CAAA;KACnB,CAAA;CACF,CAAA;;AAkFD,wBAAsC"}
1
+ {"version":3,"file":"fastifyApiReference.d.ts","sourceRoot":"","sources":["../src/fastifyApiReference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAKjD,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,sBAAsB,CAAA;CACvC,CAAA;AAQD;;GAEG;AACH,eAAO,MAAM,UAAU,i8EA+EtB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,kBAAmB,sBAAsB,WAgB/D,CAAA;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,aAAa,EAAE,sBAAsB,UAqBjE;;AA8ED,wBAAsC"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";const e=require("ejs"),n=require("fastify-plugin"),r=require("node:fs"),t=require("node:path"),i={hide:!0},s=n((async(n,s)=>{var a,o,l,c;const d=n.hasPlugin("@fastify/swagger");(null==(o=null==(a=s.apiReference)?void 0:a.spec)?void 0:o.content)||(null==(c=null==(l=s.apiReference)?void 0:l.spec)?void 0:c.url)||d?(n.route({method:"GET",url:s.routePrefix??"/",schema:i,async handler(r,i){var a,o,l,c;i.header("Content-Type","text/html; charset=utf-8");let p=s;(null==(o=null==(a=s.apiReference)?void 0:a.spec)?void 0:o.content)||(null==(c=null==(l=s.apiReference)?void 0:l.spec)?void 0:c.url)||!d||(p={...s,apiReference:{...s.apiReference,spec:{content:()=>n.swagger()}}});const u=await e.renderFile(t.resolve(`${__dirname}/../dist/templates/index.ejs`),{options:p});i.send(u)}}),n.route({method:"GET",url:(s.routePrefix??"/")+"/fastify-api-reference.js",schema:i,async handler(e,n){n.header("Content-Type","application/javascript; charset=utf-8");const i=r.readFileSync(t.resolve(`${__dirname}/../dist/templates/fastify-api-reference.js`),"utf8");n.send(i)}})):console.warn("[@scalar/fastify-api-reference] You didn’t provide a spec.content or spec.url and @fastify/swagger could not be find either. Please provide one of these options.")}));module.exports=s;
1
+ "use strict";const e=require("fastify-plugin"),n=require("node:fs"),t=require("node:path");const o={hide:!0};function r(e){return`\n<!DOCTYPE html>\n<html>\n <head>\n <title>API Reference</title>\n <meta charset="utf-8" />\n <meta\n name="viewport"\n content="width=device-width, initial-scale=1" />\n <style>\n body {\n margin: 0;\n }\n </style>\n </head>\n <body>\n ${(e=>{var n,t,o,r;return`\n <script\n id="api-reference"\n type="application/json"\n data-configuration="${JSON.stringify(e).split('"').join("&quot;")}">${(null==(n=e.spec)?void 0:n.content)?"function"==typeof(null==(t=e.spec)?void 0:t.content)?JSON.stringify(null==(o=e.spec)?void 0:o.content()):JSON.stringify(null==(r=e.spec)?void 0:r.content):""}<\/script>\n <script src="/@scalar/fastify-api-reference/browser.js"><\/script>\n `})(e)}\n </body>\n</html>\n`}const c=e((async(e,c)=>{var a,l;let{configuration:s}=c;const i=e.hasPlugin("@fastify/swagger");if(!(null==(a=null==s?void 0:s.spec)?void 0:a.content)&&!(null==(l=null==s?void 0:s.spec)?void 0:l.url)&&!i)return void console.warn("[@scalar/fastify-api-reference] You didn’t provide a spec.content or spec.url and @fastify/swagger could not be find either. Please provide one of these options.");const h=function(){const e=[t.resolve(`${__dirname}/js/standalone.js`),t.resolve(`${__dirname}/../../dist/js/standalone.js`)].find((e=>n.existsSync(e)));if(void 0===e)throw new Error(`JavaScript file not found: ${t.resolve(`${__dirname}/js/standalone.js`)}`);return n.readFileSync(e,"utf8")}();e.route({method:"GET",url:c.routePrefix??"/",schema:o,async handler(n,t){var o,c;t.header("Content-Type","text/html; charset=utf-8"),(null==(o=null==s?void 0:s.spec)?void 0:o.content)||(null==(c=null==s?void 0:s.spec)?void 0:c.url)||!i||(s={...s,spec:{content:()=>e.swagger()}}),(null==s?void 0:s.customCss)||(null==s?void 0:s.theme)||(s={...s,customCss:"\n:root {\n --theme-font: 'Inter', var(--system-fonts);\n}\n\n.light-mode {\n color-scheme: light;\n --theme-color-1: #1c1e21;\n --theme-color-2: #757575;\n --theme-color-3: #8e8e8e;\n --theme-color-disabled: #b4b1b1;\n --theme-color-ghost: #a7a7a7;\n --theme-color-accent: #2f8555;\n --theme-background-1: #fff;\n --theme-background-2: #f5f5f5;\n --theme-background-3: #ededed;\n --theme-background-4: rgba(0, 0, 0, 0.06);\n --theme-background-accent: #2f85551f;\n\n --theme-border-color: rgba(0, 0, 0, 0.1);\n --theme-scrollbar-color: rgba(0, 0, 0, 0.18);\n --theme-scrollbar-color-active: rgba(0, 0, 0, 0.36);\n --theme-lifted-brightness: 1;\n --theme-backdrop-brightness: 1;\n\n --theme-shadow-1: 0 1px 3px 0 rgba(0, 0, 0, 0.11);\n --theme-shadow-2: rgba(0, 0, 0, 0.08) 0px 13px 20px 0px,\n rgba(0, 0, 0, 0.08) 0px 3px 8px 0px, #eeeeed 0px 0 0 1px;\n\n --theme-button-1: rgb(49 53 56);\n --theme-button-1-color: #fff;\n --theme-button-1-hover: rgb(28 31 33);\n\n --theme-color-green: #007300;\n --theme-color-red: #af272b;\n --theme-color-yellow: #b38200;\n --theme-color-blue: #3b8ba5;\n --theme-color-orange: #fb892c;\n --theme-color-purple: #5203d1;\n}\n\n.dark-mode {\n color-scheme: dark;\n --theme-color-1: rgba(255, 255, 255, 0.9);\n --theme-color-2: rgba(255, 255, 255, 0.62);\n --theme-color-3: rgba(255, 255, 255, 0.44);\n --theme-color-disabled: rgba(255, 255, 255, 0.34);\n --theme-color-ghost: rgba(255, 255, 255, 0.26);\n --theme-color-accent: #27c2a0;\n --theme-background-1: #1b1b1d;\n --theme-background-2: #242526;\n --theme-background-3: #3b3b3b;\n --theme-background-4: rgba(255, 255, 255, 0.06);\n --theme-background-accent: #27c2a01f;\n\n --theme-border-color: rgba(255, 255, 255, 0.1);\n --theme-scrollbar-color: rgba(255, 255, 255, 0.24);\n --theme-scrollbar-color-active: rgba(255, 255, 255, 0.48);\n --theme-lifted-brightness: 1.45;\n --theme-backdrop-brightness: 0.5;\n\n --theme-shadow-1: 0 1px 3px 0 rgb(0, 0, 0, 0.1);\n --theme-shadow-2: rgba(15, 15, 15, 0.2) 0px 3px 6px,\n rgba(15, 15, 15, 0.4) 0px 9px 24px, 0 0 0 1px rgba(255, 255, 255, 0.1);\n\n --theme-button-1: #f6f6f6;\n --theme-button-1-color: #000;\n --theme-button-1-hover: #e7e7e7;\n\n --theme-color-green: #26b226;\n --theme-color-red: #fb565b;\n --theme-color-yellow: #ffc426;\n --theme-color-blue: #6ecfef;\n --theme-color-orange: #ff8d4d;\n --theme-color-purple: #b191f9;\n}\n.scalar-card:nth-of-type(3) {\n display: none;\n}\n"});const a=r(s);t.send(a)}}),e.route({method:"GET",url:"/@scalar/fastify-api-reference/browser.js",schema:o,async handler(e,n){n.header("Content-Type","application/javascript; charset=utf-8"),n.send(h)}})}));module.exports=c;
package/dist/index.js CHANGED
@@ -7,22 +7,149 @@ const __dirname = __getDirname();
7
7
  const __filename = __getFilename();
8
8
  const self = globalThis;
9
9
  const require2 = __createRequire(import.meta.url);
10
- import ejs from "ejs";
11
10
  import fp from "fastify-plugin";
12
11
  import fs from "node:fs";
13
12
  import path from "node:path";
13
+ function getJavaScriptFile() {
14
+ const filePath = [
15
+ path.resolve(`${__dirname}/js/standalone.js`),
16
+ path.resolve(`${__dirname}/../../dist/js/standalone.js`)
17
+ ].find((file) => fs.existsSync(file));
18
+ if (filePath === void 0) {
19
+ throw new Error(
20
+ `JavaScript file not found: ${path.resolve(
21
+ `${__dirname}/js/standalone.js`
22
+ )}`
23
+ );
24
+ }
25
+ return fs.readFileSync(filePath, "utf8");
26
+ }
14
27
  const schemaToHideRoute = {
15
28
  hide: true
16
29
  };
17
- const fastifyApiReference = async (fastify, options) => {
30
+ const defaultCss = `
31
+ :root {
32
+ --theme-font: 'Inter', var(--system-fonts);
33
+ }
34
+
35
+ .light-mode {
36
+ color-scheme: light;
37
+ --theme-color-1: #1c1e21;
38
+ --theme-color-2: #757575;
39
+ --theme-color-3: #8e8e8e;
40
+ --theme-color-disabled: #b4b1b1;
41
+ --theme-color-ghost: #a7a7a7;
42
+ --theme-color-accent: #2f8555;
43
+ --theme-background-1: #fff;
44
+ --theme-background-2: #f5f5f5;
45
+ --theme-background-3: #ededed;
46
+ --theme-background-4: rgba(0, 0, 0, 0.06);
47
+ --theme-background-accent: #2f85551f;
48
+
49
+ --theme-border-color: rgba(0, 0, 0, 0.1);
50
+ --theme-scrollbar-color: rgba(0, 0, 0, 0.18);
51
+ --theme-scrollbar-color-active: rgba(0, 0, 0, 0.36);
52
+ --theme-lifted-brightness: 1;
53
+ --theme-backdrop-brightness: 1;
54
+
55
+ --theme-shadow-1: 0 1px 3px 0 rgba(0, 0, 0, 0.11);
56
+ --theme-shadow-2: rgba(0, 0, 0, 0.08) 0px 13px 20px 0px,
57
+ rgba(0, 0, 0, 0.08) 0px 3px 8px 0px, #eeeeed 0px 0 0 1px;
58
+
59
+ --theme-button-1: rgb(49 53 56);
60
+ --theme-button-1-color: #fff;
61
+ --theme-button-1-hover: rgb(28 31 33);
62
+
63
+ --theme-color-green: #007300;
64
+ --theme-color-red: #af272b;
65
+ --theme-color-yellow: #b38200;
66
+ --theme-color-blue: #3b8ba5;
67
+ --theme-color-orange: #fb892c;
68
+ --theme-color-purple: #5203d1;
69
+ }
70
+
71
+ .dark-mode {
72
+ color-scheme: dark;
73
+ --theme-color-1: rgba(255, 255, 255, 0.9);
74
+ --theme-color-2: rgba(255, 255, 255, 0.62);
75
+ --theme-color-3: rgba(255, 255, 255, 0.44);
76
+ --theme-color-disabled: rgba(255, 255, 255, 0.34);
77
+ --theme-color-ghost: rgba(255, 255, 255, 0.26);
78
+ --theme-color-accent: #27c2a0;
79
+ --theme-background-1: #1b1b1d;
80
+ --theme-background-2: #242526;
81
+ --theme-background-3: #3b3b3b;
82
+ --theme-background-4: rgba(255, 255, 255, 0.06);
83
+ --theme-background-accent: #27c2a01f;
84
+
85
+ --theme-border-color: rgba(255, 255, 255, 0.1);
86
+ --theme-scrollbar-color: rgba(255, 255, 255, 0.24);
87
+ --theme-scrollbar-color-active: rgba(255, 255, 255, 0.48);
88
+ --theme-lifted-brightness: 1.45;
89
+ --theme-backdrop-brightness: 0.5;
90
+
91
+ --theme-shadow-1: 0 1px 3px 0 rgb(0, 0, 0, 0.1);
92
+ --theme-shadow-2: rgba(15, 15, 15, 0.2) 0px 3px 6px,
93
+ rgba(15, 15, 15, 0.4) 0px 9px 24px, 0 0 0 1px rgba(255, 255, 255, 0.1);
94
+
95
+ --theme-button-1: #f6f6f6;
96
+ --theme-button-1-color: #000;
97
+ --theme-button-1-hover: #e7e7e7;
98
+
99
+ --theme-color-green: #26b226;
100
+ --theme-color-red: #fb565b;
101
+ --theme-color-yellow: #ffc426;
102
+ --theme-color-blue: #6ecfef;
103
+ --theme-color-orange: #ff8d4d;
104
+ --theme-color-purple: #b191f9;
105
+ }
106
+ .scalar-card:nth-of-type(3) {
107
+ display: none;
108
+ }
109
+ `;
110
+ const javascript = (configuration) => {
18
111
  var _a, _b, _c, _d;
112
+ return `
113
+ <script
114
+ id="api-reference"
115
+ type="application/json"
116
+ data-configuration="${JSON.stringify(configuration).split('"').join("&quot;")}">${((_a = configuration.spec) == null ? void 0 : _a.content) ? typeof ((_b = configuration.spec) == null ? void 0 : _b.content) === "function" ? JSON.stringify((_c = configuration.spec) == null ? void 0 : _c.content()) : JSON.stringify((_d = configuration.spec) == null ? void 0 : _d.content) : ""}<\/script>
117
+ <script src="/@scalar/fastify-api-reference/browser.js"><\/script>
118
+ `;
119
+ };
120
+ function htmlDocument(configuration) {
121
+ return `
122
+ <!DOCTYPE html>
123
+ <html>
124
+ <head>
125
+ <title>API Reference</title>
126
+ <meta charset="utf-8" />
127
+ <meta
128
+ name="viewport"
129
+ content="width=device-width, initial-scale=1" />
130
+ <style>
131
+ body {
132
+ margin: 0;
133
+ }
134
+ </style>
135
+ </head>
136
+ <body>
137
+ ${javascript(configuration)}
138
+ </body>
139
+ </html>
140
+ `;
141
+ }
142
+ const fastifyApiReference = async (fastify, options) => {
143
+ var _a, _b;
144
+ let { configuration } = options;
19
145
  const hasSwaggerPlugin = fastify.hasPlugin("@fastify/swagger");
20
- if (!((_b = (_a = options.apiReference) == null ? void 0 : _a.spec) == null ? void 0 : _b.content) && !((_d = (_c = options.apiReference) == null ? void 0 : _c.spec) == null ? void 0 : _d.url) && !hasSwaggerPlugin) {
146
+ if (!((_a = configuration == null ? void 0 : configuration.spec) == null ? void 0 : _a.content) && !((_b = configuration == null ? void 0 : configuration.spec) == null ? void 0 : _b.url) && !hasSwaggerPlugin) {
21
147
  console.warn(
22
148
  "[@scalar/fastify-api-reference] You didn’t provide a spec.content or spec.url and @fastify/swagger could not be find either. Please provide one of these options."
23
149
  );
24
150
  return;
25
151
  }
152
+ const fileContent = getJavaScriptFile();
26
153
  fastify.route({
27
154
  method: "GET",
28
155
  url: options.routePrefix ?? "/",
@@ -30,41 +157,37 @@ const fastifyApiReference = async (fastify, options) => {
30
157
  // @ts-ignore
31
158
  schema: schemaToHideRoute,
32
159
  async handler(_, reply) {
33
- var _a2, _b2, _c2, _d2;
160
+ var _a2, _b2;
34
161
  reply.header("Content-Type", "text/html; charset=utf-8");
35
- let mergedOptions = options;
36
- if (!((_b2 = (_a2 = options.apiReference) == null ? void 0 : _a2.spec) == null ? void 0 : _b2.content) && !((_d2 = (_c2 = options.apiReference) == null ? void 0 : _c2.spec) == null ? void 0 : _d2.url) && hasSwaggerPlugin) {
37
- mergedOptions = {
38
- ...options,
39
- apiReference: {
40
- ...options.apiReference,
41
- // @ts-ignore
42
- spec: { content: () => fastify.swagger() }
162
+ if (!((_a2 = configuration == null ? void 0 : configuration.spec) == null ? void 0 : _a2.content) && !((_b2 = configuration == null ? void 0 : configuration.spec) == null ? void 0 : _b2.url) && hasSwaggerPlugin) {
163
+ configuration = {
164
+ ...configuration,
165
+ spec: {
166
+ content: () => {
167
+ return fastify.swagger();
168
+ }
43
169
  }
44
170
  };
45
171
  }
46
- const html = await ejs.renderFile(
47
- path.resolve(`${__dirname}/../dist/templates/index.ejs`),
48
- {
49
- options: mergedOptions
50
- }
51
- );
172
+ if (!(configuration == null ? void 0 : configuration.customCss) && !(configuration == null ? void 0 : configuration.theme)) {
173
+ configuration = {
174
+ ...configuration,
175
+ customCss: defaultCss
176
+ };
177
+ }
178
+ const html = htmlDocument(configuration);
52
179
  reply.send(html);
53
180
  }
54
181
  });
55
182
  fastify.route({
56
183
  method: "GET",
57
- url: (options.routePrefix ?? "/") + "/fastify-api-reference.js",
184
+ url: "/@scalar/fastify-api-reference/browser.js",
58
185
  // We don’t know whether @fastify/swagger is registered, but it doesn’t hurt to add a schema anyway.
59
186
  // @ts-ignore
60
187
  schema: schemaToHideRoute,
61
188
  async handler(_, reply) {
62
189
  reply.header("Content-Type", "application/javascript; charset=utf-8");
63
- const content = fs.readFileSync(
64
- path.resolve(`${__dirname}/../dist/templates/fastify-api-reference.js`),
65
- "utf8"
66
- );
67
- reply.send(content);
190
+ reply.send(fileContent);
68
191
  }
69
192
  });
70
193
  };