Want to subscribe to topics you're interested in?
Become a Member

add_header 'Access-Control-Allow-Origin

Discussion in 'Blogs & CMS usage' started by Max, Oct 28, 2024.

  1. Max

    Max Member

    124
    5
    18
    Feb 17, 2018
    Ratings:
    +9
    Local Time:
    12:05 PM
    Hello is set in the .conf
    location /.well-known {
    if ($request_method = 'GET') {
    add_header 'Access-Control-Allow-Origin' '*';
    }
    }

    but cors Tester say
    This URL will not work correctly with CORS.
    is the code correct?

    thanks

     
  2. eva2000

    eva2000 Administrator Staff Member

    54,361
    12,198
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,763
    Local Time:
    10:05 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    What are you trying to achieve ?

    Maybe

    Code (Text):
    location /.well-known {
        if ($request_method = 'GET') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
            add_header 'Access-Control-Allow-Headers' '*';
        }
        
        # Handle OPTIONS requests to satisfy CORS preflight
        if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
            add_header 'Access-Control-Allow-Headers' '*';
            add_header 'Access-Control-Max-Age' 86400;
            return 204;  # No Content for OPTIONS
        }
    }
     
  3. Max

    Max Member

    124
    5
    18
    Feb 17, 2018
    Ratings:
    +9
    Local Time:
    12:05 PM
    Hello
    the code does not work
    it must be possible to read the .well-know/nostr.json file from other websites

    Code:
    ยง Self hosted verification
    
    If you already own a domain, this is a free option. You just need to add a .well-known/nostr.json file to your domain. The contents of the file should be the following:
    
    {
        "names": {
            "YOUR_NOSTR_NAME": "YOUR_NOSTR_PUBLIC_KEY"
        }
    }
    
    Optionally you can also add a section to let clients know which relays they are likely to find you on:
    
    {
      "names": {
        "YOUR_NOSTR_NAME": "YOUR_NOSTR_PUBLIC_KEY_IN_HEX_FORMAT"
      },
      "relays": {
        "YOUR_NOSTR_PUBLIC_KEY_IN_HEX_FORMAT": [
          "wss://relay.one",
          "wss://relay.two",
          ...
        ]
      }
    }
    
    

     
  4. eva2000

    eva2000 Administrator Staff Member

    54,361
    12,198
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,763
    Local Time:
    10:05 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Maybe

    Code:
    location /.well-known/nostr.json {
        add_header Access-Control-Allow-Origin "*";
        add_header Access-Control-Allow-Methods "GET, OPTIONS";
        add_header Access-Control-Allow-Headers "Content-Type";
        if ($request_method = 'OPTIONS') {
            return 204;
        }
    }
     
  5. Max

    Max Member

    124
    5
    18
    Feb 17, 2018
    Ratings:
    +9
    Local Time:
    12:05 PM