From d7f330c5f5a21fab2331777c5cd22a6c46d913f7 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Sat, 4 Apr 2020 21:47:35 +0200 Subject: [PATCH 1/2] fix: support POST-only HTTP API ipfs/go-ipfs#7097 will block `GET` commands on API port, switching everything to POST. This breaks Files screen in ipfs-webui as noted in ipfs-shipyard/ipfs-webui#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 --- package-lock.json | 65 +++++++++++++++++++ package.json | 2 + patches/ipfs-http-client+39.0.2.patch | 91 +++++++++++++++++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 patches/ipfs-http-client+39.0.2.patch diff --git a/package-lock.json b/package-lock.json index b633912b6..ff8e1cedb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5530,6 +5530,11 @@ "resolved": "https://registry.npmjs.org/@xtuc/long/-/long-4.2.2.tgz", "integrity": "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==" }, + "@yarnpkg/lockfile": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz", + "integrity": "sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ==" + }, "abab": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.3.tgz", @@ -11522,6 +11527,27 @@ "locate-path": "^3.0.0" } }, + "find-yarn-workspace-root": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/find-yarn-workspace-root/-/find-yarn-workspace-root-1.2.1.tgz", + "integrity": "sha512-dVtfb0WuQG+8Ag2uWkbG79hOUzEsRrhBzgfn86g2sJPkzmcpGdghbNTfUKGTxymFrY/tLIodDzLoW9nOJ4FY8Q==", + "requires": { + "fs-extra": "^4.0.3", + "micromatch": "^3.1.4" + }, + "dependencies": { + "fs-extra": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-4.0.3.tgz", + "integrity": "sha512-q6rbdDd1o2mAnQreO7YADIxf/Whx4AHBiRf6d+/cVT8h44ss+lHgxf1FemcqDnQt9X3ct4McHr+JMGlYSsK7Cg==", + "requires": { + "graceful-fs": "^4.1.2", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + } + } + }, "flat-cache": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-2.0.1.tgz", @@ -40970,6 +40996,14 @@ "graceful-fs": "^4.1.9" } }, + "klaw-sync": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/klaw-sync/-/klaw-sync-6.0.0.tgz", + "integrity": "sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ==", + "requires": { + "graceful-fs": "^4.1.11" + } + }, "kleur": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", @@ -43297,6 +43331,37 @@ "resolved": "https://registry.npmjs.org/pascalcase/-/pascalcase-0.1.1.tgz", "integrity": "sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ=" }, + "patch-package": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/patch-package/-/patch-package-6.2.2.tgz", + "integrity": "sha512-YqScVYkVcClUY0v8fF0kWOjDYopzIM8e3bj/RU1DPeEF14+dCGm6UeOYm4jvCyxqIEQ5/eJzmbWfDWnUleFNMg==", + "requires": { + "@yarnpkg/lockfile": "^1.1.0", + "chalk": "^2.4.2", + "cross-spawn": "^6.0.5", + "find-yarn-workspace-root": "^1.2.1", + "fs-extra": "^7.0.1", + "is-ci": "^2.0.0", + "klaw-sync": "^6.0.0", + "minimist": "^1.2.0", + "rimraf": "^2.6.3", + "semver": "^5.6.0", + "slash": "^2.0.0", + "tmp": "^0.0.33" + }, + "dependencies": { + "fs-extra": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", + "integrity": "sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==", + "requires": { + "graceful-fs": "^4.1.2", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + } + } + }, "path-browserify": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-0.0.1.tgz", diff --git a/package.json b/package.json index cf79e1368..2af30e6cd 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/patches/ipfs-http-client+39.0.2.patch b/patches/ipfs-http-client+39.0.2.patch new file mode 100644 index 000000000..dbd8f5f33 --- /dev/null +++ b/patches/ipfs-http-client+39.0.2.patch @@ -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, From 5d3c6b39c24728e38bec93612d9ee32e60973e65 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Sat, 4 Apr 2020 22:54:45 +0200 Subject: [PATCH 2/2] docs: remove GET from CORS setup for API --- README.md | 2 +- cors-config.sh | 2 +- src/welcome/WelcomePage.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d24c1c932..3ca747288 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cors-config.sh b/cors-config.sh index c2a73a73b..04eec20ef 100755 --- a/cors-config.sh +++ b/cors-config.sh @@ -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" diff --git a/src/welcome/WelcomePage.js b/src/welcome/WelcomePage.js index ba2add7cb..457215549 100644 --- a/src/welcome/WelcomePage.js +++ b/src/welcome/WelcomePage.js @@ -74,7 +74,7 @@ const ConnectionStatus = ({ t, connected, sameOrigin }) => { $ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '[{addOrigin && `"${origin}", `}"{defaultDomains.join('", "')}"]' - $ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST"]' + $ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "POST"]' )}