cortesi/devd

Does websocket protocol work?

aellerton opened this issue · 6 comments

Hi,

Love devd!

I'm having trouble reverse proxying the ws protocol. The following runs:

devd -H /api/=http://localhost:8080/api /ws/=http://localhost:8080/ws public/

... but attempts to access the websocket (which work without devd) fail with:

WebSocket connection to 'ws://localhost:8000/ws' failed: Error during WebSocket handshake: Unexpected response code: 301

Thanks!
A

Hmm, wondering if the proxy headers mentioned here will be useful...

socketio/socket.io#1942

Hi there. Unfortunately, devd doesn't currently have the ability to proxy Websocket. I wouldn't be against adding the ability to do this, but it would be quite a significant amount of work to do.

No worries. Totally understand.

It may be worth adding a warning when the proxy host starts with ws::. If I get time I'll do a PR...

I have also hit the need for this, please consider adding support.

@phubbard devd is awesome but if you need websocket support, it's worth just firing up nginx. More fuss to set up and heavier to run, true, but works a treat.

On top of that if you run nginx on port 80 and modify your /etc/hosts or modify the real DNS entry to 127.0.0.1 then your development url can look nice and clean like ``http://dev.anything.com/`.

I know, small things, but it's a nice end result.

Yeah, ideally you can use mkcert to get a real cert for a local domain, and dnsmasq to adjust the domain name. The proxy could be nginx, caddy, traefik or devd.

brew install caddy mkcert nss dnsmasq

mkcert -install
# test could be anything
mkcert '*.app.test' '*.cdn.test'

# rename the certs and move them under /usr/local/etc/caddy/certs

cat <<EOF > /usr/local/etc/caddy/Caddyfile
*.app.test:443, *.cdn.test:443 {
  tls /usr/local/etc/caddy/certs/dev.pem /usr/local/etc/caddy/certs/dev-key.pem
  gzip
  proxy / localhost:3000 {
    transparent
  }
}
EOF

cat <<EOF >> /usr/local/etc/dnsmasq.conf
port=53
address=/.test/127.0.0.1
EOF

sudo echo "nameserver 127.0.0.1" > /etc/resolver/test

sudo brew services start dnsmasq

scutil --dns
# dnsmasq setup is successful if you see an entry for test domain like this:
# resolver #8
#   domain   : test
#   nameserver[0] : 127.0.0.1
#   flags    : Request A records, Request AAAA records
#   reach    : 0x00030002 (Reachable,Local Address,Directly Reachable Address)

sudo caddy -conf /usr/local/etc/caddy/Caddyfile
# optional: configure launchd to have caddy run on startup