diff --git a/src/core/config/defaults.js b/src/core/config/defaults.js index ef2daf7db41..2ff789852ec 100644 --- a/src/core/config/defaults.js +++ b/src/core/config/defaults.js @@ -15,7 +15,7 @@ const defaultOptions = Object.freeze({ maxDisplayedTags: -1, filter: false, validatorUrl: "https://validator.swagger.io/validator", - oauth2RedirectUrl: `${window.location.protocol}//${window.location.host}${window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"))}/oauth2-redirect.html`, + oauth2RedirectUrl: undefined, persistAuthorization: false, configs: {}, custom: {}, diff --git a/src/core/config/index.js b/src/core/config/index.js index e0b7d94544a..a789b0b1f15 100644 --- a/src/core/config/index.js +++ b/src/core/config/index.js @@ -3,5 +3,6 @@ export { default as storeOptionsFactorization } from "./factorization/store" export { default as optionsFromQuery } from "./sources/query" export { default as optionsFromURL } from "./sources/url" export { default as optionsFromSystem } from "./sources/system" +export { default as optionsFromRuntime } from "./sources/runtime" export { default as defaultOptions } from "./defaults" export { default as mergeOptions } from "./merge" diff --git a/src/core/config/sources/runtime.js b/src/core/config/sources/runtime.js new file mode 100644 index 00000000000..38cb4af7c48 --- /dev/null +++ b/src/core/config/sources/runtime.js @@ -0,0 +1,18 @@ +/** + * @prettier + * + * Receives options at runtime. + */ + +/* eslint-disable no-undef */ +const optionsFromRuntime = () => () => { + const options = {} + + if (globalThis.location) { + options.oauth2RedirectUrl = `${globalThis.location.protocol}//${globalThis.location.host}${globalThis.location.pathname.substring(0, globalThis.location.pathname.lastIndexOf("/"))}/oauth2-redirect.html` + } + + return options +} + +export default optionsFromRuntime diff --git a/src/core/index.js b/src/core/index.js index 1274d332487..bb4bb933386 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -34,6 +34,7 @@ import { optionsFromQuery, optionsFromURL, optionsFromSystem, + optionsFromRuntime, mergeOptions, inlinePluginOptionsFactorization, storeOptionsFactorization @@ -42,7 +43,8 @@ import { export default function SwaggerUI(userOptions) { const queryOptions = optionsFromQuery()(userOptions) - let mergedOptions = mergeOptions({}, defaultOptions, userOptions, queryOptions) + const runtimeOptions = optionsFromRuntime()() + let mergedOptions = mergeOptions({}, defaultOptions, runtimeOptions, userOptions, queryOptions) const storeOptions = storeOptionsFactorization(mergedOptions) const InlinePlugin = inlinePluginOptionsFactorization(mergedOptions) @@ -57,7 +59,7 @@ export default function SwaggerUI(userOptions) { .then((urlOptions) => { const urlOptionsFailedToFetch = urlOptions === null - mergedOptions = mergeOptions({}, defaultOptions, systemOptions, userOptions, urlOptions, queryOptions) + mergedOptions = mergeOptions({}, defaultOptions, runtimeOptions, systemOptions, userOptions, urlOptions, queryOptions) store.setConfigs(mergedOptions) system.configsActions.loaded()