The 'Access-Control-Allow-Origin' header has a value 'http://localhost:4200' that is not equal to the supplied origin

前端 未结 7 2522
清酒与你
清酒与你 2020-12-20 12:33

(continuation of error message in title) \" Origin \'http://127.0.0.1:4200\' is therefore not allowed access.\"

I am unable to run the same Angular 5 site on two dif

7条回答
  •  孤城傲影
    2020-12-20 13:01

    Setup a reverse proxy server and configure paths for both the domains.
    Nginx Guide

    This will allow you to access everything via http://localhost/
    Let's assume:
    A -> Angular App (localhost:4200)
    B -> Your other domain API (myapitest.local)

    Example Flow:
    - Browser Request(http://localhost/angular) -> Nginx -> A
    - Load Data from backend -> Nginx -> B

    So, with the help of Nginx, you will be able to access "A" from http://localhost/ and "B" also from http://localhost/
    Since, the origin is same, there will be no CORS error.

提交回复
热议问题