Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow CORS mode to be optional #60

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const Webflow = require('webflow-api');
// Initialize the API
const api = new Webflow({ token: 'api-token' });

// Initialize the API without CORS mode
const apiNoCors = new Webflow({ token: 'api-token', fetchOpts: { mode: undefined }});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is left over as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a leftover. This is how you would accomplish the removal of cors mode with the fetch options override approach you suggested instead of the useCors: false approach from the first pass.


// Fetch a site
api.site({ siteId: '580e63e98c9a982ac9b8b741' }).then(site => console.log(site));
```
Expand All @@ -32,6 +35,7 @@ The `Webflow` constructor takes several options to initialize the API client:

* `token` - the API token **(required)**
* `version` - the version of the API you wish to use (optional)
* `fetchOpts` - an option to override `fetch` options

All of the API methods are documented in the [API documentation](https://developers.webflow.com).

Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ declare namespace Webflow {
token: string;
endpoint?: string;
version?: string;
fetchOpts?: RequestInit;
}

namespace WebflowApiModel {
Expand Down
3 changes: 2 additions & 1 deletion src/Webflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const responseHandler = (res) =>
});

export default class Webflow {
constructor({ endpoint = DEFAULT_ENDPOINT, token, version = "1.0.0" } = {}) {
constructor({ endpoint = DEFAULT_ENDPOINT, token, version = "1.0.0", fetchOpts = {} } = {}) {
if (!token) throw buildRequiredArgError("token");

this.responseWrapper = new ResponseWrapper(this);
Expand All @@ -76,6 +76,7 @@ export default class Webflow {
method,
headers: this.headers,
mode: "cors",
Copy link
Contributor

@johnagan johnagan Aug 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left over from the original PR

...fetchOpts,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing about this approach is it would override the headers (including auth) if someone added a header entry.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. Could change the order:

mode: "cors",
...fetchOpts,
method,
headers: this.headers,

I think this would do the trick. Thoughts?

};

if (data) {
Expand Down