Skip to content

Commit 945315e

Browse files
authored
fix: support POST-only HTTP API (#1430)
* 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
1 parent 24db4d0 commit 945315e

File tree

6 files changed

+161
-3
lines changed

6 files changed

+161
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Run the **[cors-config.sh](./cors-config.sh)** script with:
7171

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

7777
#### Reverting

cors-config.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ALLOW_ORIGINS='"http://localhost:3000", "https://webui.ipfs.io"'
66
set -e
77

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

1111
echo "IPFS API CORS headers configured for $ALLOW_ORIGINS"
1212
echo "Please restart your IPFS daemon"

package-lock.json

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "2.7.2",
44
"private": true,
55
"scripts": {
6+
"postinstall": "patch-package",
67
"start": "run-script-os",
78
"start:win32": "@powershell -Command $env:REACT_APP_GIT_REV=(git rev-parse --short HEAD); react-scripts start",
89
"start:darwin:linux": "cross-env REACT_APP_GIT_REV=`git rev-parse --short HEAD` react-scripts start",
@@ -55,6 +56,7 @@
5556
"multiaddr": "^7.2.1",
5657
"multiaddr-to-uri": "^5.1.0",
5758
"p-queue": "^6.2.1",
59+
"patch-package": "6.2.2",
5860
"prop-types": "^15.7.2",
5961
"pull-file-reader": "^1.0.2",
6062
"react": "^16.12.0",

patches/ipfs-http-client+39.0.2.patch

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
diff --git a/node_modules/ipfs-http-client/src/config/profiles/list.js b/node_modules/ipfs-http-client/src/config/profiles/list.js
2+
index dbfa579..6f501f7 100644
3+
--- a/node_modules/ipfs-http-client/src/config/profiles/list.js
4+
+++ b/node_modules/ipfs-http-client/src/config/profiles/list.js
5+
@@ -8,7 +8,7 @@ module.exports = configure(({ ky }) => {
6+
return callbackify.variadic(async (options) => {
7+
options = options || {}
8+
9+
- const res = await ky.get('config/profile/list', {
10+
+ const res = await ky.post('config/profile/list', {
11+
timeout: options.timeout,
12+
signal: options.signal,
13+
headers: options.headers
14+
diff --git a/node_modules/ipfs-http-client/src/files-regular/get.js b/node_modules/ipfs-http-client/src/files-regular/get.js
15+
index 6c94264..68e15fe 100644
16+
--- a/node_modules/ipfs-http-client/src/files-regular/get.js
17+
+++ b/node_modules/ipfs-http-client/src/files-regular/get.js
18+
@@ -36,7 +36,7 @@ module.exports = configure(({ ky }) => {
19+
searchParams.set('length', options.length)
20+
}
21+
22+
- const res = await ky.get('get', {
23+
+ const res = await ky.post('get', {
24+
timeout: options.timeout,
25+
signal: options.signal,
26+
headers: options.headers,
27+
diff --git a/node_modules/ipfs-http-client/src/files-regular/ls.js b/node_modules/ipfs-http-client/src/files-regular/ls.js
28+
index 0f13f55..d81a963 100644
29+
--- a/node_modules/ipfs-http-client/src/files-regular/ls.js
30+
+++ b/node_modules/ipfs-http-client/src/files-regular/ls.js
31+
@@ -31,7 +31,7 @@ module.exports = configure(({ ky }) => {
32+
searchParams.set('recursive', options.recursive)
33+
}
34+
35+
- const res = await ky.get('ls', {
36+
+ const res = await ky.post('ls', {
37+
timeout: options.timeout,
38+
signal: options.signal,
39+
headers: options.headers,
40+
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
41+
index efb8d32..afa1630 100644
42+
--- a/node_modules/ipfs-http-client/src/files-regular/refs-local.js
43+
+++ b/node_modules/ipfs-http-client/src/files-regular/refs-local.js
44+
@@ -9,7 +9,7 @@ module.exports = configure(({ ky }) => {
45+
return async function * refsLocal (options) {
46+
options = options || {}
47+
48+
- const res = await ky.get('refs/local', {
49+
+ const res = await ky.post('refs/local', {
50+
timeout: options.timeout,
51+
signal: options.signal,
52+
headers: options.headers
53+
diff --git a/node_modules/ipfs-http-client/src/files-regular/refs.js b/node_modules/ipfs-http-client/src/files-regular/refs.js
54+
index c6136ed..dbeb9a1 100644
55+
--- a/node_modules/ipfs-http-client/src/files-regular/refs.js
56+
+++ b/node_modules/ipfs-http-client/src/files-regular/refs.js
57+
@@ -49,7 +49,7 @@ module.exports = configure(({ ky }) => {
58+
searchParams.append('arg', arg.toString())
59+
}
60+
61+
- const res = await ky.get('refs', {
62+
+ const res = await ky.post('refs', {
63+
timeout: options.timeout,
64+
signal: options.signal,
65+
headers: options.headers,
66+
diff --git a/node_modules/ipfs-http-client/src/pubsub/ls.js b/node_modules/ipfs-http-client/src/pubsub/ls.js
67+
index 177dcd4..d2bc8f6 100644
68+
--- a/node_modules/ipfs-http-client/src/pubsub/ls.js
69+
+++ b/node_modules/ipfs-http-client/src/pubsub/ls.js
70+
@@ -6,7 +6,7 @@ module.exports = configure(({ ky }) => {
71+
return async (options) => {
72+
options = options || {}
73+
74+
- const { Strings } = await ky.get('pubsub/ls', {
75+
+ const { Strings } = await ky.post('pubsub/ls', {
76+
timeout: options.timeout,
77+
signal: options.signal,
78+
headers: options.headers,
79+
diff --git a/node_modules/ipfs-http-client/src/pubsub/peers.js b/node_modules/ipfs-http-client/src/pubsub/peers.js
80+
index bdeca60..5fa5b24 100644
81+
--- a/node_modules/ipfs-http-client/src/pubsub/peers.js
82+
+++ b/node_modules/ipfs-http-client/src/pubsub/peers.js
83+
@@ -14,7 +14,7 @@ module.exports = configure(({ ky }) => {
84+
const searchParams = new URLSearchParams(options.searchParams)
85+
searchParams.set('arg', topic)
86+
87+
- const { Strings } = await ky.get('pubsub/peers', {
88+
+ const { Strings } = await ky.post('pubsub/peers', {
89+
timeout: options.timeout,
90+
signal: options.signal,
91+
headers: options.headers,

src/welcome/WelcomePage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const ConnectionStatus = ({ t, connected, sameOrigin }) => {
7474
</Trans>
7575
<Shell>
7676
<code className='db'>$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '[{addOrigin && `"${origin}", `}"{defaultDomains.join('", "')}"]'</code>
77-
<code className='db'>$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST"]'</code>
77+
<code className='db'>$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "POST"]'</code>
7878
</Shell>
7979
</div>
8080
)}

0 commit comments

Comments
 (0)