Skip to content

Commit 872a11e

Browse files
committed
fix: base docs domain
1 parent 7539406 commit 872a11e

File tree

1 file changed

+99
-1
lines changed

1 file changed

+99
-1
lines changed

src/components/ScalarApiReference.astro

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,32 @@ interface Props {
55
}
66
77
const {specURL, proxyURL = import.meta.env.PUBLIC_KINDE_PROXY_URL} = Astro.props;
8+
9+
// Build configuration object
10+
const config: Record<string, any> = {
11+
theme: "deepSpace",
12+
hideDarkModeToggle: "true",
13+
searchHotKey: "j",
14+
servers: [
15+
{
16+
url: "https://{your_kinde_subdomain}.kinde.com",
17+
variables: {
18+
your_kinde_subdomain: {
19+
default: "your_kinde_subdomain"
20+
}
21+
}
22+
}
23+
]
24+
};
25+
26+
const configString = JSON.stringify(config);
827
---
928

1029
<script
1130
id="api-reference"
1231
data-url={specURL}
1332
data-proxy-url={proxyURL}
14-
data-configuration='{"theme": "deepSpace", "hideDarkModeToggle": "true", "searchHotKey": "j"}'
33+
data-configuration={configString}
1534
></script>
1635
<script
1736
src="https://cdn.jsdelivr.net/npm/@scalar/[email protected]/dist/browser/standalone.min.js"
@@ -20,6 +39,85 @@ const {specURL, proxyURL = import.meta.env.PUBLIC_KINDE_PROXY_URL} = Astro.props
2039
<script>
2140
import waitForElement from "@utils/waitForElement";
2241

42+
// Configure servers after Scalar loads
43+
const targetServers = [
44+
{
45+
url: "https://{your_kinde_subdomain}.kinde.com",
46+
variables: {
47+
your_kinde_subdomain: {
48+
default: "your_kinde_subdomain"
49+
}
50+
}
51+
}
52+
];
53+
54+
function updateScalarServers() {
55+
const apiReferenceElement = document.getElementById("api-reference");
56+
if (!apiReferenceElement) return;
57+
58+
// Method 1: Try to access Scalar's internal API
59+
const scalarInstance = (window as any).ScalarApiReference;
60+
if (scalarInstance && scalarInstance.updateConfiguration) {
61+
scalarInstance.updateConfiguration({
62+
servers: targetServers
63+
});
64+
return;
65+
}
66+
67+
// Method 2: Access the parsed spec directly
68+
const scalarRef = (apiReferenceElement as any).__scalarApiReference;
69+
if (scalarRef) {
70+
if (scalarRef.spec) {
71+
scalarRef.spec.servers = targetServers;
72+
if (scalarRef.update) {
73+
scalarRef.update();
74+
}
75+
}
76+
// Also try to update configuration
77+
if (scalarRef.configuration) {
78+
scalarRef.configuration.servers = targetServers;
79+
}
80+
}
81+
82+
// Method 3: Update server selector in DOM if it exists
83+
const serverSelect = document.querySelector('.scalar-api-reference select[data-scalar-server], .scalar-api-reference .server-selector select');
84+
if (serverSelect) {
85+
const serverUrl = targetServers[0].url;
86+
(serverSelect as HTMLSelectElement).value = serverUrl;
87+
serverSelect.dispatchEvent(new Event('change', { bubbles: true }));
88+
}
89+
90+
// Method 4: Find and update base URL display
91+
const baseUrlElement = document.querySelector('.scalar-api-reference .base-url, .scalar-api-reference a.base-url');
92+
if (baseUrlElement) {
93+
baseUrlElement.textContent = targetServers[0].url.replace('{your_kinde_subdomain}', 'your_kinde_subdomain');
94+
}
95+
}
96+
97+
// Wait for Scalar to load and then update servers
98+
waitForElement(".scalar-api-reference", () => {
99+
// Try multiple times as Scalar might load async
100+
setTimeout(updateScalarServers, 500);
101+
setTimeout(updateScalarServers, 1000);
102+
setTimeout(updateScalarServers, 2000);
103+
104+
// Also watch for changes in the DOM (server selector might load later)
105+
const observer = new MutationObserver(() => {
106+
updateScalarServers();
107+
});
108+
109+
const scalarContainer = document.querySelector('.scalar-api-reference');
110+
if (scalarContainer) {
111+
observer.observe(scalarContainer, {
112+
childList: true,
113+
subtree: true
114+
});
115+
116+
// Stop observing after 5 seconds to avoid performance issues
117+
setTimeout(() => observer.disconnect(), 5000);
118+
}
119+
});
120+
23121
// Wait for subdomain input to be ready, then focus and select text on focus, making it easier for users to enter their Kinde subdomain
24122
waitForElement("#variable-subdomain", (inputElement: HTMLInputElement) => {
25123
inputElement.addEventListener("focus", () => {

0 commit comments

Comments
 (0)