1 | ;
|
2 | /**
|
3 | * @license
|
4 | * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
|
5 | * This code may only be used under the BSD style license found at
|
6 | * http://polymer.github.io/LICENSE.txt
|
7 | * The complete set of authors may be found at
|
8 | * http://polymer.github.io/AUTHORS.txt
|
9 | * The complete set of contributors may be found at
|
10 | * http://polymer.github.io/CONTRIBUTORS.txt
|
11 | * Code distributed by Google as part of the polymer project is also
|
12 | * subject to an additional IP rights grant found at
|
13 | * http://polymer.github.io/PATENTS.txt
|
14 | */
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | const url_1 = require("url");
|
17 | /**
|
18 | * Resolves requests via the the DOM fetch API.
|
19 | */
|
20 | class FetchUrlLoader {
|
21 | constructor(baseUrl) {
|
22 | this.baseUrl = baseUrl;
|
23 | }
|
24 | _resolve(url) {
|
25 | return this.baseUrl ? url_1.resolve(this.baseUrl, url) : url;
|
26 | }
|
27 | canLoad(_) {
|
28 | return true;
|
29 | }
|
30 | load(url) {
|
31 | return window.fetch(this._resolve(url)).then((response) => {
|
32 | if (response.ok) {
|
33 | return response.text();
|
34 | }
|
35 | else {
|
36 | return response.text().then((content) => {
|
37 | throw new Error(`Response not ok: ${content}`);
|
38 | });
|
39 | }
|
40 | });
|
41 | }
|
42 | }
|
43 | exports.FetchUrlLoader = FetchUrlLoader;
|
44 | //# sourceMappingURL=fetch-url-loader.js.map |
\ | No newline at end of file |