Can’t determine the source of a CORS error

I have an Angular app whose build I am trying to run on an nginx docker container accessible at http://localhost:4001/. All 4001 resources load correctly, but the javascript bundle makes an xhr request to https:localhost:5001/foo/bar (note port and scheme change) that is blocked by firefox (“CORS failed”): a dotnet core app hosted in another docker container.

Here’s the nginx config, with everything opened up for local testing.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code># Config file for nginx docker container for local development. Not used for production releases.
events{}
http {
include /etc/nginx/mime.types;
server {
listen 4001;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
location ~ /* {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Credentials' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH' always;
add_header 'Access-Control-Allow-Headers' 'Accept, Accept-Language, Content-Language, Content-Type, Authorization, Origin, Referer, User-Agent, Cache-Control, DNT, If-Modified-Since, Range' always;
add_header 'Access-Control-Expose-Headers' '*' always;
if ($request_method = 'OPTIONS' ) {
return 204 no-content;
}
try_files $uri $uri/ =404;
}
}
}
</code>
<code># Config file for nginx docker container for local development. Not used for production releases. events{} http { include /etc/nginx/mime.types; server { listen 4001; server_name localhost; root /usr/share/nginx/html; index index.html; location ~ /* { add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Credentials' '*' always; add_header 'Access-Control-Allow-Methods' 'GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH' always; add_header 'Access-Control-Allow-Headers' 'Accept, Accept-Language, Content-Language, Content-Type, Authorization, Origin, Referer, User-Agent, Cache-Control, DNT, If-Modified-Since, Range' always; add_header 'Access-Control-Expose-Headers' '*' always; if ($request_method = 'OPTIONS' ) { return 204 no-content; } try_files $uri $uri/ =404; } } } </code>
# Config file for nginx docker container for local development. Not used for production releases.
events{}
http {
    include /etc/nginx/mime.types;
    server {
        listen 4001;
        server_name localhost;
        root /usr/share/nginx/html;
        index index.html;
        location ~ /* {
            add_header 'Access-Control-Allow-Origin' '*' always;
            add_header 'Access-Control-Allow-Credentials' '*' always;
            add_header 'Access-Control-Allow-Methods' 'GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH' always;
            add_header 'Access-Control-Allow-Headers' 'Accept, Accept-Language, Content-Language, Content-Type, Authorization, Origin, Referer, User-Agent, Cache-Control, DNT, If-Modified-Since, Range' always;
            add_header 'Access-Control-Expose-Headers' '*' always;
            if ($request_method = 'OPTIONS' ) {
                return 204 no-content;
            }
            try_files $uri $uri/ =404;
        }
    }
}

I have verified that the headers are present on the response to http://localhost:4001/ and the js bundle http://localhost:4001/polyfills.js (in particular, the following are copied from the raw response):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: *
Access-Control-Allow-Methods: GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH
Access-Control-Allow-Headers: Accept, Accept-Language, Content-Language, Content-Type, Authorization, Origin, Referer, User-Agent, Cache-Control, DNT, If-Modified-Since, Range
Access-Control-Expose-Headers: *
</code>
<code>Access-Control-Allow-Origin: * Access-Control-Allow-Credentials: * Access-Control-Allow-Methods: GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH Access-Control-Allow-Headers: Accept, Accept-Language, Content-Language, Content-Type, Authorization, Origin, Referer, User-Agent, Cache-Control, DNT, If-Modified-Since, Range Access-Control-Expose-Headers: * </code>
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: *
Access-Control-Allow-Methods: GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH
Access-Control-Allow-Headers: Accept, Accept-Language, Content-Language, Content-Type, Authorization, Origin, Referer, User-Agent, Cache-Control, DNT, If-Modified-Since, Range
Access-Control-Expose-Headers: *

Clearly the headers returned by http://localhost:4001/ aren’t allowing the script loaded by that page to call https://localhost:5001/foo/bar; why not, and what do I change to allow this xhr call?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật