mfractal commented on issue #7082:
URL: https://github.com/apache/apisix/issues/7082#issuecomment-1561145265

   Encountered the same issue myself. 
   Thought i'd dump the solution here in case anybody else needs it.
   
   We have a few routes with the following to allow routing the the right 
graphql server according to a header called graphqlName.
   
   ```
   match:
           paths:
             - /api/graphql/*
             - /api/graphql
           exprs:
             - subject:
                 scope: Header
                 name: graphqlName
               op: In
               set: {{- trim (toYaml $.Values.routes.graphqlOperations) | 
nindent 12 }}
   ```
   
   So when the client calls `/api/graphql` and sends an `OPTIONS` request it'll 
not get routed anywhere since match conditions are skipped for OPTIONS and 
there was no route to serve the request. 
   I ended up creating a new route just for OPTIONS requests 
   
   ```
   apiVersion: apisix.apache.org/v2
   kind: ApisixRoute
   metadata:
     name: options-graphql
     namespace: ${var.namespace_name}
   spec:
     http:
     - backends:
       - serviceName: webserver
         servicePort: http
       match:
         methods:
         - OPTIONS
         paths:
         - /api/graphql/*
         - /api/graphql
       name: options-graphql
       plugin_config_name: routes-default
       plugins:
       - config:
           regex_uri:
           - ^/api/?(.*)
           - /$1
         enable: true
         name: proxy-rewrite
   ```
   and the plugin config
   ```
   apiVersion: apisix.apache.org/v2
   kind: ApisixPluginConfig
   metadata:
     name: routes-default
     namespace: ${var.namespace_name}
   spec:
     plugins:
     - config:
         allow_credential: true
         allow_headers: 
keep-alive,authorization,user-agent,cache-control,content-type,content-transfer-encoding,accountId,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout,graphqlName
         allow_methods: GET, POST, PUT, DELETE, PATCH, OPTIONS
         allow_origins: ${var.cors_allow_origins}
         expose_headers: grpc-status,grpc-message
       enable: true
       name: cors
     - config:
         conf:
         - name: webserver.${var.namespace_name}
           value: "9090"
       enable: true
       name: ext-plugin-post-req
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to