Skip to content

Commit

Permalink
Support dynamic api doc server address
Browse files Browse the repository at this point in the history
  • Loading branch information
cb-github-robot authored Oct 2, 2024
2 parents a7422f7 + fba2db9 commit bddc152
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 9 additions & 2 deletions redoc-swagger.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,15 @@

console.log('Starting to fetch YAML');

const protocol = window.location.protocol;
const hostname = window.location.hostname;
const apiPort = '1323';
const apiDocPath = '/tumblebug/api/doc.yaml';
const apiDocUrl = `${protocol}//${hostname}:${apiPort}${apiDocPath}`;

console.log('API Document URL:', apiDocUrl);
// Fetch the YAML file with authentication
fetch('http://localhost:1323/tumblebug/api/doc.yaml', {
fetch(apiDocUrl, {
headers: {
'Authorization': authHeader
}
Expand All @@ -114,7 +121,7 @@

// Initialize Swagger UI (placed on the right side)
const ui = SwaggerUIBundle({
url: 'http://localhost:1323/tumblebug/api/doc.yaml',
url: apiDocUrl,
dom_id: '#swagger-ui-container',
presets: [
SwaggerUIBundle.presets.apis,
Expand Down
12 changes: 9 additions & 3 deletions swagger.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,16 @@
const credentials = btoa(username + ':' + password);
const authHeader = 'Basic ' + credentials;

console.log('Starting to fetch YAML');
const protocol = window.location.protocol;
const hostname = window.location.hostname;
const apiPort = '1323';
const apiDocPath = '/tumblebug/api/doc.yaml';
const apiDocUrl = `${protocol}//${hostname}:${apiPort}${apiDocPath}`;

console.log('API Document URL:', apiDocUrl);

// Fetch the YAML file with authentication
fetch('http://localhost:1323/tumblebug/api/doc.yaml', {
fetch(apiDocUrl, {
headers: {
'Authorization': authHeader
}
Expand All @@ -81,7 +87,7 @@

// Initialize Swagger UI
const ui = SwaggerUIBundle({
url: 'http://localhost:1323/tumblebug/api/doc.yaml',
url: apiDocUrl,
dom_id: '#swagger-ui-container',
presets: [
SwaggerUIBundle.presets.apis,
Expand Down

0 comments on commit bddc152

Please sign in to comment.