Skip to content

Instantly share code, notes, and snippets.

@tanish-kr
Created December 7, 2018 08:59
Show Gist options
  • Save tanish-kr/239528751b0eae385ec0e3104eb351ff to your computer and use it in GitHub Desktop.
Save tanish-kr/239528751b0eae385ec0e3104eb351ff to your computer and use it in GitHub Desktop.

Swagger NetworkError

Swaggerでheaderを付与したリクエストで発生

nginx側でAccess-Control-Allow-Headersにリクエストするヘッダーkeyを追加して解決

    if ($cros = 'true') {
          add_header 'swagger' '2.0' always;
          #add_header 'Access-Control-Allow-Origin' '*' always;
          add_header 'Access-Control-Allow-Origin' "$http_origin" always;
          add_header 'Access-Control-Allow-Credentials' 'true' always;
          add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS';
          add_header Access-Control-Allow-Headers 'Origin, Authorization, Accept, Content-Type, HOGE-KEY';
          add_header 'Access-Control-Expose-Headers' 'Authorization' always;
        }

        if ($option_method = 'true') {
          #add_header Access-Control-Allow-Origin '*';
          add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS';
          add_header 'Access-Control-Allow-Origin' "$http_origin" always;
          add_header 'Access-Control-Allow-Credentials' 'true' always;
          add_header Access-Control-Allow-Headers 'Origin, Authorization, Accept, Content-Type, HOGE-KEY';
          add_header Access-Control-Max-Age 3600;
          add_header 'Access-Control-Expose-Headers' 'Authorization' always;
          add_header Content-Type 'text/plain charset=UTF-8';
          add_header Content-Length 0;

          return 204;
        }

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