Skip to content

Commit

Permalink
fix: support POST-only HTTP API (#1430)
Browse files Browse the repository at this point in the history
* fix: support POST-only HTTP API

ipfs/kubo#7097 will block `GET` commands on
API port, switching everything to POST.

This breaks Files screen in ipfs-webui as noted in
#1429

ipfs-webui is using older version of js-ipfs-http-client, one before
huge refactor into async iterables, which means switching to the latest
version won't be a trivial task.

For now, we just apply simple patch on top of ipfs-http-client v39.0.2
to ensure it sends commands as POST.

Proper fix will land when ipfs-webui is refactored to work with
ipfs-http-client >41.x

Closes #1429

* docs: remove GET from CORS setup for API
  • Loading branch information
lidel authored Apr 4, 2020
1 parent 24db4d0 commit 945315e
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Run the **[cors-config.sh](./cors-config.sh)** script with:

```sh
> ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://localhost:3000", "https://webui.ipfs.io"]'
> ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST"]'
> ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "POST"]'
```

#### Reverting
Expand Down
2 changes: 1 addition & 1 deletion cors-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ALLOW_ORIGINS='"http://localhost:3000", "https://webui.ipfs.io"'
set -e

ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin "[$ALLOW_ORIGINS]"
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "POST"]'

echo "IPFS API CORS headers configured for $ALLOW_ORIGINS"
echo "Please restart your IPFS daemon"
65 changes: 65 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "2.7.2",
"private": true,
"scripts": {
"postinstall": "patch-package",
"start": "run-script-os",
"start:win32": "@powershell -Command $env:REACT_APP_GIT_REV=(git rev-parse --short HEAD); react-scripts start",
"start:darwin:linux": "cross-env REACT_APP_GIT_REV=`git rev-parse --short HEAD` react-scripts start",
Expand Down Expand Up @@ -55,6 +56,7 @@
"multiaddr": "^7.2.1",
"multiaddr-to-uri": "^5.1.0",
"p-queue": "^6.2.1",
"patch-package": "6.2.2",
"prop-types": "^15.7.2",
"pull-file-reader": "^1.0.2",
"react": "^16.12.0",
Expand Down
91 changes: 91 additions & 0 deletions patches/ipfs-http-client+39.0.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
diff --git a/node_modules/ipfs-http-client/src/config/profiles/list.js b/node_modules/ipfs-http-client/src/config/profiles/list.js
index dbfa579..6f501f7 100644
--- a/node_modules/ipfs-http-client/src/config/profiles/list.js
+++ b/node_modules/ipfs-http-client/src/config/profiles/list.js
@@ -8,7 +8,7 @@ module.exports = configure(({ ky }) => {
return callbackify.variadic(async (options) => {
options = options || {}

- const res = await ky.get('config/profile/list', {
+ const res = await ky.post('config/profile/list', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers
diff --git a/node_modules/ipfs-http-client/src/files-regular/get.js b/node_modules/ipfs-http-client/src/files-regular/get.js
index 6c94264..68e15fe 100644
--- a/node_modules/ipfs-http-client/src/files-regular/get.js
+++ b/node_modules/ipfs-http-client/src/files-regular/get.js
@@ -36,7 +36,7 @@ module.exports = configure(({ ky }) => {
searchParams.set('length', options.length)
}

- const res = await ky.get('get', {
+ const res = await ky.post('get', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
diff --git a/node_modules/ipfs-http-client/src/files-regular/ls.js b/node_modules/ipfs-http-client/src/files-regular/ls.js
index 0f13f55..d81a963 100644
--- a/node_modules/ipfs-http-client/src/files-regular/ls.js
+++ b/node_modules/ipfs-http-client/src/files-regular/ls.js
@@ -31,7 +31,7 @@ module.exports = configure(({ ky }) => {
searchParams.set('recursive', options.recursive)
}

- const res = await ky.get('ls', {
+ const res = await ky.post('ls', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
diff --git a/node_modules/ipfs-http-client/src/files-regular/refs-local.js b/node_modules/ipfs-http-client/src/files-regular/refs-local.js
index efb8d32..afa1630 100644
--- a/node_modules/ipfs-http-client/src/files-regular/refs-local.js
+++ b/node_modules/ipfs-http-client/src/files-regular/refs-local.js
@@ -9,7 +9,7 @@ module.exports = configure(({ ky }) => {
return async function * refsLocal (options) {
options = options || {}

- const res = await ky.get('refs/local', {
+ const res = await ky.post('refs/local', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers
diff --git a/node_modules/ipfs-http-client/src/files-regular/refs.js b/node_modules/ipfs-http-client/src/files-regular/refs.js
index c6136ed..dbeb9a1 100644
--- a/node_modules/ipfs-http-client/src/files-regular/refs.js
+++ b/node_modules/ipfs-http-client/src/files-regular/refs.js
@@ -49,7 +49,7 @@ module.exports = configure(({ ky }) => {
searchParams.append('arg', arg.toString())
}

- const res = await ky.get('refs', {
+ const res = await ky.post('refs', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
diff --git a/node_modules/ipfs-http-client/src/pubsub/ls.js b/node_modules/ipfs-http-client/src/pubsub/ls.js
index 177dcd4..d2bc8f6 100644
--- a/node_modules/ipfs-http-client/src/pubsub/ls.js
+++ b/node_modules/ipfs-http-client/src/pubsub/ls.js
@@ -6,7 +6,7 @@ module.exports = configure(({ ky }) => {
return async (options) => {
options = options || {}

- const { Strings } = await ky.get('pubsub/ls', {
+ const { Strings } = await ky.post('pubsub/ls', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
diff --git a/node_modules/ipfs-http-client/src/pubsub/peers.js b/node_modules/ipfs-http-client/src/pubsub/peers.js
index bdeca60..5fa5b24 100644
--- a/node_modules/ipfs-http-client/src/pubsub/peers.js
+++ b/node_modules/ipfs-http-client/src/pubsub/peers.js
@@ -14,7 +14,7 @@ module.exports = configure(({ ky }) => {
const searchParams = new URLSearchParams(options.searchParams)
searchParams.set('arg', topic)

- const { Strings } = await ky.get('pubsub/peers', {
+ const { Strings } = await ky.post('pubsub/peers', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
2 changes: 1 addition & 1 deletion src/welcome/WelcomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const ConnectionStatus = ({ t, connected, sameOrigin }) => {
</Trans>
<Shell>
<code className='db'>$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '[{addOrigin && `"${origin}", `}"{defaultDomains.join('", "')}"]'</code>
<code className='db'>$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST"]'</code>
<code className='db'>$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "POST"]'</code>
</Shell>
</div>
)}
Expand Down

0 comments on commit 945315e

Please sign in to comment.