bl1231 / bilbomd-ui

Frontend React SPA webapp for new BilboMD
2 stars 0 forks source link

Put `bilbomd-backend` API behind a proxy? #71

Closed dsclassen closed 7 months ago

dsclassen commented 1 year ago

Read up on webpack dev server here

dsclassen commented 9 months ago

This has been done. While preparing to deploy via Helm to the NERSC Kubernetes cluster I had a brain wave. Essentially since bilbomd-ui is served from an nginx container instead of sending API traffic to a dedicated exposed backend port 3500 we send all API traffic to our nginx server and reverse proxy it within the namespace to http://backend:3500

doing it with this config:

server {
    listen       80;
    server_name  localhost;

    client_max_body_size 100M;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html;
    }

    location /api {
        client_max_body_size 80M;
        proxy_pass http://backend:3500;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

The problem is that when deploying via docker compose poxy_pass is different than when deploying to Kubernetes/NERSC. For now I must manually edit the value:

docker compose = http://bilbomd-prod-backend-1:3500 docker compose = http://bilbomd-dev-backend-1:3500 kubernetes = http://backend:3500

At some point I'll need to figure out how to deal with this in a better way.

dsclassen commented 7 months ago

closing, as this is the new way