Nginx authenticate against backend server with j_security_check

266 Views Asked by At

I need a reverse proxy for a backend Rest API to avoid CORS and debugging issues while developing a Svelte App. I've tried a few options like Node JS Express with http-proxy-middleware, Nginx, etc. The problem is that the backend JAX-RS Rest API requires j_security_check authentication. My modest network protocol skills run out trying to configure that in the proxy...

How would I make the following work:

Svelte App (http:5000) -> Proxy (http:3333) -> Rest API (http:8080 w/j_security_check)

So for example:

Svelte:

const ping = async () => {
    const response = await fetch('http://localhost:3333/api/ping', {
        method: 'GET',
        headers: {
            Accept: 'application/json',
        },
    });
    return await response.json();
};

Nginx so far:

location /api/ {
    add_header Access-Control-Allow-Origin "http://localhost:5000";
    add_header Access-Control-Allow-Methods "GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH";
    proxy_pass http://backend:8080/;
    proxy_set_header Host $host;
}

I guess I'm missing a lot of header config from the above. If it's even possible for j_security_check.

Since this is local development proxy only, it would be optimal if the proxy could handle the authentication and leave those details hidden from the Svelte App.

0

There are 0 best solutions below