Search code examples
node.jsreverse-proxyipfs

Running a local dev IPFS gateway that supports HTTPS


I'm building a distributed web app designed to be hosted on IPFS. I want to do development in a web browser, using my local gateway to serve my files, but I use Javascript APIs that are not permitted without being served off HTTPS.

I tried starting a reverse proxy with self-signed ssl pointing at my local IPFS http gateway, but when I visit links using the reverse proxy, say https://___hashhere___.ipfs.localhost:8081/, I'm redirected to http://___hashhere___.ipfs.localhost:8080/:

GATEWAY_PORT=$(ipfs config Addresses.Gateway | cut -d'/' -f 5)
HTTPS_PORT=$((GATEWAY_PORT+1))

echo "https proxy to your ipfs gateway now at: https://localhost:$HTTPS_PORT"
exec npx local-ssl-proxy --source $HTTPS_PORT --target $GATEWAY_PORT

How can I run a local https+ipfs gateway in a command or two? I guess I need a reverse proxy that rewrites URLs in responses?


Solution

    • If you use Chromium-based browser, then http://___hashhere___.ipfs.localhost:8080/ will have window.isSecureContext set to true and you will have access to all Web APIs. No need for TLS setup for dev on localhost with Chromium (Firefox has a bug).

    • If you are running IPFS Companion, you may want to disable it when you develop your app, to ensure requests for IPFS resources are not redirected to the gateway set in browser extension's Preferences.

    • In production, you deploy go-ipfs behind a reverse proxy and that proxy terminates TLS. You can control the protocol scheme and host used in some of redirects via X-Forwarded-Proto and X-Forwarded-Host headers, as noted in go-ipfs/docs/config.md