diff --git a/README.md b/README.md index 2d8d70f70..13d55d74e 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ ipfs-api - [Install](#install) - [Running the daemon with the right port](#running-the-daemon-with-the-right-port) - [Importing the module and usage](#importing-the-module-and-usage) - - [In the Browser through browserify](#in-the-browser-through-browserify) - - [In the Browser through ` ``` -This will export the `IpfsApi` constructor on the `window` object, such that: +For maximum security you may also decide to: + +* reference a specific version of IPFS API (to prevent unexpected breaking changes when a newer latest version is published) + +* [generate a SRI hash](https://www.srihash.org/) of that version and use it to ensure integrity + +* set the [CORS settings attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes) to make anonymous requests to CDN + +Example: + +```html + +``` + +CDN-based IPFS API provides the `IpfsApi` constructor as a method of the global `window` object. Example: ``` var ipfs = window.IpfsApi('localhost', '5001') ``` -If you omit the host and port, the api will parse `window.host`, and use this information. This also works, and can be useful if you want to write apps that can be run from multiple different gateways: +If you omit the host and port, the API will parse `window.host`, and use this information. This also works, and can be useful if you want to write apps that can be run from multiple different gateways: ``` var ipfs = window.IpfsApi() @@ -95,7 +113,7 @@ var ipfs = window.IpfsApi() ### CORS -If are using this module in a browser with something like browserify, then you will get an error saying that the origin is not allowed. This would be a CORS ("Cross Origin Resource Sharing") failure. The ipfs server rejects requests from unknown domains by default. You can whitelist the domain that you are calling from by changing your ipfs config like this: +In a web browser IPFS API (either browserified or CDN-based) might encounter an error saying that the origin is not allowed. This would be a CORS ("Cross Origin Resource Sharing") failure: IPFS servers are designed to reject requests from unknown domains by default. You can whitelist the domain that you are calling from by changing your ipfs config like this: ```bash $ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin "[\"http://example.com\"]"