Skip to content

Commit 09e0dd2

Browse files
committed
check whether window.location is defined to work on React Native
1 parent 637756a commit 09e0dd2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/client.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ SwaggerClient.prototype.initialize = function (url, options) {
125125

126126
if(this.url && this.url.indexOf('http:') === -1 && this.url.indexOf('https:') === -1) {
127127
// no protocol, so we can only use window if it exists
128-
if(typeof(window) !== 'undefined' && window && window.location) {
128+
if(typeof(window) !== 'undefined' && typeof(window.location) !== 'undefined') {
129129
this.url = window.location.origin + this.url;
130130
}
131131
}
@@ -346,18 +346,18 @@ SwaggerClient.prototype.buildFromSpec = function (response) {
346346
if (typeof this.url === 'string') {
347347
location = this.parseUri(this.url);
348348
if (typeof this.scheme === 'undefined' && typeof this.schemes === 'undefined' || this.schemes.length === 0) {
349-
if(typeof window !== 'undefined') {
349+
if(typeof window !== 'undefined' && typeof(window.location) !== 'undefined') {
350350
// use the window scheme
351351
this.scheme = window.location.protocol.replace(':','');
352352
}
353353
else {
354354
this.scheme = location.scheme || 'http';
355355
}
356-
} else if (typeof window !== 'undefined' && window.location.protocol.indexOf('chrome-extension') === 0) {
356+
} else if (typeof window !== 'undefined' && typeof(window.location) !== 'undefined' && window.location.protocol.indexOf('chrome-extension') === 0) {
357357
// if it is chrome swagger ui extension scheme then let swagger doc url scheme decide the protocol
358358
this.scheme = location.scheme;
359359
} else if (typeof this.scheme === 'undefined') {
360-
if(typeof window !== 'undefined') {
360+
if(typeof window !== 'undefined' && typeof(window.location) !== 'undefined') {
361361
var scheme = window.location.protocol.replace(':','');
362362
if(scheme === 'https' && this.schemes.indexOf(scheme) === -1) {
363363
// can't call http from https served page in a browser!

0 commit comments

Comments
 (0)