1. Caddy version (caddy version
):
I’m using Docker caddy:2.1.1
2. How I run Caddy:
I’m running Caddy using docker-compose
with this config:
frontend:
image: caddy:2.1.1-alpine
volumes:
- ./build:/usr/share/caddy
- ./Caddyfile:/etc/caddy/Caddyfile
ports:
- 3000:3000
- 3001:443
networks:
- my_network
build
is the destination directory of React (HTML and JS files)
a. System environment:
I’m running it on Mac using docker-compose
b. Command:
# described above
docker-compose up -d frontend
c. Service/unit/compose file:
version: "3.8"
services:
frontend:
image: caddy:2.1.1-alpine
volumes:
- ./build:/usr/share/caddy
- ./Caddyfile:/etc/caddy/Caddyfile
ports:
- 3000:3000
- 3001:443
networks:
- mynetwork
backend:
build:
context: ./backend
ports:
- 8000:8000
environment:
- DATABASE_URL=postgres://******
networks:
- mynetwork
postgres:
image: postgres:13.0
environment:
- POSTGRES_USER=****
- POSTGRES_PASSWORD=***
- POSTGRES_DB=****
ports:
- 5432:5432
networks:
- mynetwork
networks:
mynetwork:
driver: bridge
d. My complete Caddyfile or JSON config:
I’m using Caddyfile
localhost:3000 {
root * /usr/share/caddy
@websockets {
header Connection *Upgrade*
header Upgrade websocket
}
reverse_proxy @websockets localhost:8000/graphql
route {
reverse_proxy /graphql backend:8000
try_files {path} {path}/ /index.html?{query}
file_server
}
log {
output stdout
}
}
3. The problem I’m having:
Hi
I’m trying to deploy React app using GraphQL backend that support subscription through Web Sockets.
The backend has only one route /graphql
where client is using HTTP and WebSocket requests. I want to serve the app using Caddy and redirect all “api requests” to backend micro-service.
The HTTP requests went well but no matter what I tried I didn’t find a way to serve Websocket.
I’m getting on Chrome:
client.ts:557 WebSocket connection to 'ws://localhost:3000/graphql' failed: Error during WebSocket handshake: Unexpected response code: 400
and can’t find relevant log in Caddy
4. Error messages and/or full log output:
No error messages in Caddy output
5. What I already tried:
Couldn’t find in the web neither this forum a solution
6. Links to relevant resources:
no relevant resources