Pass the browser cors preflight with response status 204 for Method OPTIONS
Requirements: Traefik >= v2.5.5
--pilot.token=xxx--experimental.plugins.corspreflight.modulename=github.com/Medzoner/traefik-plugin-cors-preflight--experimental.plugins.corspreflight.version=v1.0.7
pilot:token: xxxexperimental:plugins:corspreflight:modulename: github.com/Medzoner/traefik-plugin-cors-preflightversion: v1.0.7
[pilot]token = "xxx"[experimental.plugins.corspreflight]modulename = "github.com/Medzoner/traefik-plugin-cors-preflight"version = "v1.0.7"
testData:testData:code: 204method: 'OPTIONS'
To configure the CorsPreflight
plugin you should create a middleware in your dynamic configuration as explained here.
http:middlewares:corspreflight-middleware:plugin:corspreflight:code: 200method: OPTIONSrouters:my-router:rule: Host(`localhost`)middlewares:- corspreflight-middlewareservice: my-serviceservices:my-service:loadBalancer:servers:- url: 'http://127.0.0.1'
[http.middlewares][http.middlewares.corspreflight-middleware.plugin.corspreflight]code = 200method = "OPTIONS"[http.routers][http.routers.my-router]rule = "Host(`localhost`)"middlewares = ["corspreflight-middleware"]service = "my-service"[http.services][http.services.my-service][http.services.my-service.loadBalancer][[http.services.my-service.loadBalancer.servers]]url = "http://127.0.0.1"
---apiVersion: traefik.containo.us/v1alpha1kind: Middlewaremetadata:name: corspreflight-middlewarespec:plugin:corspreflight:code: 200method: OPTIONS---apiVersion: traefik.containo.us/v1alpha1kind: IngressRoutemetadata:name: whoamispec:entryPoints:- webroutes:- kind: Rulematch: Host(`whoami.localhost`)middlewares:- name: corspreflight-middlewareservices:- kind: Servicename: whoami-svcport: 80
---apiVersion: traefik.containo.us/v1alpha1kind: Middlewaremetadata:name: corspreflight-middlewarespec:plugin:corspreflight:code: 200method: OPTIONS---apiVersion: networking.k8s.io/v1kind: Ingressmetadata:name: myingressannotations:traefik.ingress.kubernetes.io/router.middlewares: default-corspreflight-middleware@kubernetescrdspec:rules:- host: whoami.localhosthttp:paths:- path: /pathType: Prefixbackend:service:name: whoamiport:number: 80
version: '3.7'services:whoami:image: traefik/whoami:v1.7.1labels:traefik.enable: 'true'traefik.http.routers.app.rule: Host(`whoami.localhost`)traefik.http.routers.app.entrypoints: websecuretraefik.http.routers.app.middlewares: corspreflight-middlewaretraefik.http.middlewares.corspreflight-middleware.plugin.corspreflight.code: 200traefik.http.middlewares.corspreflight-middleware.plugin.corspreflight.method: 'OPTIONS'