diff --git a/src/index.ts b/src/index.ts index 52c468a..36c24ce 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,10 +25,12 @@ export class MediaWikiApi { constructor(baseURL?: string, options?: Partial) { // For MediaWiki environment if (!baseURL && typeof window === 'object' && (window as any).mediaWiki) { - const scriptPath: string | undefined = ( - window as any - ).mediaWiki?.config?.get('wgScriptPath') - typeof scriptPath === 'string' && (baseURL = `${scriptPath}/api.php`) + const { wgServer, wgScriptPath } = + (window as any).mediaWiki?.config?.get(['wgServer', 'wgScriptPath']) || + {} + if (typeof wgServer === 'string' && typeof wgScriptPath === 'string') { + baseURL = `${wgServer}${wgScriptPath}/api.php` + } } if (typeof baseURL !== 'string') { throw new Error('baseURL is undefined')