Setting up websockets with caddy so I can connect go-ipfs with js-ipfs

I’m trying to setup a gateway that exposes my node to a js-ipfs browser based, so that I can reliably send pub-sub messages. I find that unless I connect to the same peers the pubsub messages get lost. I’m trying to use docker and caddy. My question is basically, how do I configure the websocket connection on the go-ipfs side, and what is the initial swarm that I’ll need on the browser js-ipfs side?

Here’s the current setup. Test machine name is

docker create network identity

docker run --name ipfs \
        -d --restart unless-stopped \
        -p 4001:4001 \
        -p \
        -p \
        --network identity \
        -v ${IPFSDATA}:/data/ipfs \
        -v ${IPFSSTAGING}:/export \
        -m 900m\
        ipfs/go-ipfs \
        daemon --writable --enable-pubsub-experiment


docker run --name caddy \
        -d --restart unless-stopped \
        -p 80:80 -p 443:443 \
        --network identity \
        -v ${PWD}/html:/html \
        -v ${CADDYFILE}:/etc/Caddyfile \
        -v ${ACCESSLOG}:/src/access.log \
        -v caddy_keys:/root/.caddy \
        -e ACME_AGREE=true \
        -e HOSTNAME=${HOSTNAME} \


root /html
errors error.log

proxy /ipfs/ http://ipfs:8080/ 

proxy /ws http://ipfs:8081 {

And then I’ve set inside of the config file:

  "Addresses": {
    "API": "/ip4/",
    "Announce": [],
    "Gateway": "/ip4/",
    "NoAnnounce": [],
    "Swarm": [

And my node test code:

const IPFS = require('ipfs')

const node = new IPFS({
  config: {
    Addresses: {
      Swarm: [

console.log( "Connecting" )
node.on('ready', async () => {
  const version = await

  console.log( version )

  console.log( "Peers" )

  const peers = await node.swarm.peers()


So my questions are:

  1. What am I doing wrong? :slight_smile:
  2. What is the right path to proxy from Caddy to the ipfs websocket server? I’m using /ws on my public facing proxy server to proxy to the 8081 port?
  3. What should my initial swam address be in the node side? I’m using '/dns4/' but it doesn’t show any peers or error messages?
  4. How do I debug js-ipfs better? Why is it silently starting?
  5. Is there something special I need to do to enable p2p-websocket-star on the go-ipfs side?

Been banging my head against this but there are too many things I don’t understand to move forward… Thanks in advance.

I think you should use / for the websocket path in Caddy. Do you see anything in (Caddy) logs?

As far as I’m aware p2p-websocket-star is a separate service that go-ipfs doesn’t provide (seems to be

I think that you should use /dns4/ as a bootstrap peer (I’m not sure how that’s handled in js-ipfs). You should be also ablo to call ipfs.swarm.connect('/dns4/') and see that connection in browser.

If you want the browser node to be able to talk to the outside, try following

OK so I never figured it out with caddy, but I wrote up how to do it with docker-compose, nginx and certbot