Skip to content

Commit

Permalink
fix(fetch): add fetchOptions property to control fetch options
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Wensink committed Jan 7, 2018
1 parent 5369bd4 commit 665447b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Site {

// Created when initializing
private url: string;
private fetchOptions: RequestInit;

// Can be hydrated and dehydrated
private tokensToVerify: string[];
Expand All @@ -30,10 +31,11 @@ class Site {
if (initParams) this.initialize(initParams);
}

initialize({ url }: SiteInitializeParams) {
initialize({ url, fetchOptions = {} }: SiteInitializeParams) {
if (this.initialized) throw Error('The site is already initialized.');
this.initialized = true;
this.url = url;
this.fetchOptions = fetchOptions;
}

reset() {
Expand Down Expand Up @@ -78,6 +80,7 @@ class Site {
mode: 'cors',
cache: 'default',
...options,
...this.fetchOptions,
})
.then((response) => {
if (!response.ok) {
Expand Down
1 change: 1 addition & 0 deletions src/SiteInitializeParams.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default interface SiteInitializeParams {
url: string;
fetchOptions?: RequestInit;
}

0 comments on commit 665447b

Please sign in to comment.