Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save akhdaniel/0ac3817e277558bb4a590a8abd345146 to your computer and use it in GitHub Desktop.
Save akhdaniel/0ac3817e277558bb4a590a8abd345146 to your computer and use it in GitHub Desktop.
CORS issues on nginx, odoo, rest/jsonrpc API

Di nginx.conf atau site-enabled/yourdomain.conf, tambahkan entyr berikut di dalam directive "location /"

location / {

        # Simple requests
        #
        if ($request_method ~* "(GET|POST)") {
              add_header Access-Control-Allow-Origin "*" always;
              add_header Access-Control-Allow-Headers "Authorization, Origin, X-Requested-With, Content-Type, Accept, Connection, Accept-Language, Content-Language, Referer, Set-Cookie, Cookie";
              add_header Access-Control-Allow-Credentials true;
              add_header Access-Control-Expose-Headers "*";
        }

        # Preflighted requests
        if ($request_method = OPTIONS ) {
              add_header Access-Control-Allow-Origin "*" always;
              add_header Access-Control-Allow-Methods "GET, POST, OPTIONS, PUT, PATCH, DELETE";
              add_header Access-Control-Allow-Headers "Authorization, Origin, X-Requested-With, Content-Type, Accept, Connection, Accept-Language, Content-Language, Referer, Set-Cookie, Cookie";
              add_header Access-Control-Allow-Credentials true;
              add_header Access-Control-Request-Headers "access-control-allow-credentials,content-type,set-cookie,cookie";
              return 200;
        }



         ...
         ...
         
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment