problem with reverse proxy angular application in docker container

Discussão em 'Angular' iniciado por Elax46, Outubro 26, 2024.

  1. Elax46

    Elax46 Guest

    I'm creating an application in angular that needs access to an API (not created by me) that unfortunately has a CORS policy that does not allow execution so I solved the problem by using reverse proxy locally everything works correctly and I can extract the data from the API the problem arises when I try to create a docker container as the url set as the proxy target is replaced with the container's url

    proxy.conf.json

    {
    "/api": {
    "target": "https://myurl",
    "secure": true,
    "changeOrigin": true,
    "pathRewrite": {
    "^/api": ""
    }
    }
    }


    nginx.conf

    server {

    listen 8081;
    server_name localhost;


    location /api/taxation_customs {
    proxy_pass https://myurl;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    }


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


    Dockerfile

    FROM node:latest AS build

    WORKDIR /usr/local/app


    COPY ./ /usr/local/app/


    RUN npm install


    RUN npm run build


    FROM nginx:latest


    COPY --from=build /usr/local/app/dist/generatore/browser /usr/share/nginx/html



    COPY nginx.conf /etc/nginx/conf.d/default.conf

    EXPOSE 8081

    Continue reading...

Compartilhe esta Página