0

I'm trying to use regex capture functions for create an Access-Control-Origin header.

So y have two main capture, one for the adress of website ( likehttp://example.com) and another for the port user (such as :4200).

The idea is having this header : Origin: http://example.com:4200

My capture work for the first case but it seem to don't like the port.

I get Origin : http://example.com: instead of Origin: http://example.com:4200

Here is my nginx config :

My guess is that Access-Control-Allow-Origin don't understant numerical value.

    if ($request_uri ~ ^/api/blabla/*){
          set $public "1";
    }

    if ($http_origin ~* (https?:\/\/[^/]*(localhost|\.example.com))(:[0-9]+)?[^\w\d]) {
         set $public "${public}1";
    } 
    if ($public = "11"){
         set $http_origin_regex $1$4;
         add_header 'Access-Control-Allow-Origin' "$http_origin_regex";
    }
P0pR0cK5
  • 290
  • 1
  • 6

1 Answers1

0

look at http://marcel.zurreck.com/enable-cross-origin-requests-cors-nginx/

using their syntax I got:

location ~ ^/api/blabla/ {
    if ($http_origin ~* (https?://[^/]*(localhost|\.example\.com)(:[0-9]+)?)) {
        add_header 'Access-Control-Allow-Origin' "$http_origin";
    }
}
Tamar
  • 186
  • 2