in a development environment I need to access my client and all of my backend services using localhost:80. Therefore I want to use haproxy to map the requests to the right services.
I created the following Dockerfile to start an haproxy:
FROM haproxy:1-alpine
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
My haproxy.cfg file looks like this:
defaults
timeout client 30s
timeout server 30s
timeout connect 30s
frontend MyFrontend
bind *:80
acl url_api path_reg ^/api-.*
use_backend api-backend if url_api
default_backend web-backend
backend api-backend
mode http
server backend host.docker.internal:8080
backend web-backend
mode http
server client host.docker.internal:4200
I start the docker machine using the following command:
docker build -t haproxy-local . && docker run --rm -p80:80 haproxy-local
My angular client is started on the host machine on port 4200. My backend service on port 8080 is running to. If I access http://localhost:80 my web client is opened in the web browser. Unfortunately if I try to access the backend using http://localhost/api-my-backend-service/123 it does not work. If I change it to
default_backend api-backend
I can access the backend via http://localhost/api-my-backend-service/12 but not the client.
So the access to both backends does seem to work because if I change the default backend I can access both client and api backend. But the use_backend does not seem to match and I am unable to figure out why.
Any ideas?
Thanks Meinert