From 13cb808ce6e416797f91011de3fa153640eb644b Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Mon, 4 Jun 2018 11:01:02 +0200 Subject: [PATCH] fix: check if 'location' exists on Document object NativeScript has a fake global 'document' object, which doesn't have a 'location' property. This PR introduces a check that the 'location' property is defined before retrieving it and allows the package to be used with NativeScript. --- src/in-mem/backend.service.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/in-mem/backend.service.ts b/src/in-mem/backend.service.ts index 7639fad..d259f29 100644 --- a/src/in-mem/backend.service.ts +++ b/src/in-mem/backend.service.ts @@ -438,10 +438,11 @@ export abstract class BackendService { */ protected getLocation(url: string): UriInfo { if (!url.startsWith('http')) { - // get the document iff running in browser + // get the document if running in browser const doc: Document = (typeof document === 'undefined') ? undefined : document; // add host info to url before parsing. Use a fake host when not in browser. - const base = doc ? doc.location.protocol + '//' + doc.location.host : 'http://fake'; + const { location } = doc; + const base = location ? location.protocol + '//' + location.host : 'http://fake'; url = url.startsWith('/') ? base + url : base + '/' + url; } return parseUri(url);