I'm using skipper as a part of kubernetes ingress controller.
I've added custom HTTP headers with annotations:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
zalando.org/skipper-routes: |
Method("GET") ->
setResponseHeader("Access-Control-Allow-Origin", "https://mydomain.com") ->
setResponseHeader("Access-Control-Allow-Methods", "*") ->
setResponseHeader("Access-Control-Allow-Headers", "Authorization") ->
setResponseHeader("Access-Control-Allow-Credentials", "true") ->
status(200) -> <shunt>
I can't find any information how to add same headers for other methods at the same time. I would like to add POST and OPTIONS.
I think you want to use https://godoc.org/github.com/zalando/skipper/filters/cors, which provides a much cleaner solution from the user point of view.
Use it with zalando.org/skipper-filter annotation
@szuecs cors filter only takes care of Access-Control-Allow-Origin with multiple origins.
the rest is still fine to specify statically.
@szuecs thanks!
@ruiaraujo Can I create multiple static routes? Like:
```
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
zalando.org/skipper-routes: |
Method("GET") ->
setResponseHeader("Access-Control-Allow-Origin", "https://mydomain.com") ->
setResponseHeader("Access-Control-Allow-Methods", "") ->
setResponseHeader("Access-Control-Allow-Headers", "Authorization") ->
setResponseHeader("Access-Control-Allow-Credentials", "true") ->
status(200) ->
Method("POST") ->
setResponseHeader("Access-Control-Allow-Origin", "https://mydomain.com") ->
setResponseHeader("Access-Control-Allow-Methods", "
setResponseHeader("Access-Control-Allow-Headers", "Authorization") ->
setResponseHeader("Access-Control-Allow-Credentials", "true") ->
status(200) ->
Hi @pavel-letskii ,
yes you can add multiple routes in the annotation, but with minor differences, something like this:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
zalando.org/skipper-routes: |
getFoo: Method("GET") ->
setResponseHeader("Access-Control-Allow-Origin", "https://mydomain.com") ->
setResponseHeader("Access-Control-Allow-Methods", "*") ->
setResponseHeader("Access-Control-Allow-Headers", "Authorization") ->
setResponseHeader("Access-Control-Allow-Credentials", "true") ->
status(200) -> <shunt>;
postFoo: Method("POST") ->
setResponseHeader("Access-Control-Allow-Origin", "https://mydomain.com") ->
setResponseHeader("Access-Control-Allow-Methods", "*") ->
setResponseHeader("Access-Control-Allow-Headers", "Authorization") ->
setResponseHeader("Access-Control-Allow-Credentials", "true") ->
status(200) -> <shunt>;
The difference is basically adding route ids (getFoo and postFoo), and separating the routes with semicolons. Pls let us know how it works out.
@aryszka we could also have a Method defined with varargs, which would simplify the definition here and probably in others, too.
Most helpful comment
@aryszka we could also have a Method defined with varargs, which would simplify the definition here and probably in others, too.