Skip to content

Commit

Permalink
Merge pull request #12 from moegirlwiki/dragon-fish/patch-auto-endpoint
Browse files Browse the repository at this point in the history
fix: auto endpoint (close #11)
  • Loading branch information
dragon-fish authored Aug 14, 2023
2 parents dbf1146 + a70246b commit faee982
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ export class MediaWikiApi {
constructor(baseURL?: string, options?: Partial<FexiosConfigs>) {
// 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')
Expand Down

0 comments on commit faee982

Please sign in to comment.