/Cors Preflight

Cors Preflight

8
v1.0.7

Traefik Plugin: CORS Preflight

Build Status Coverage Status License Go report

Short Description

Pass the browser cors preflight with response status 204 for Method OPTIONS

Configuration

Requirements: Traefik >= v2.5.5

Static

--pilot.token=xxx
--experimental.plugins.corspreflight.modulename=github.com/Medzoner/traefik-plugin-cors-preflight
--experimental.plugins.corspreflight.version=v1.0.4
pilot:
token: xxx
experimental:
plugins:
corspreflight:
modulename: github.com/Medzoner/traefik-plugin-cors-preflight
version: v1.0.4
[pilot]
token = "xxx"
[experimental.plugins.corspreflight]
modulename = "github.com/Medzoner/traefik-plugin-cors-preflight"
version = "v1.0.4"
testData:
testData:
Code: 204
Method: 'OPTIONS'

Dynamic

To configure the CorsPreflight plugin you should create a middleware in your dynamic configuration as explained here.

File

http:
middlewares:
corspreflight-middleware:
plugin:
corspreflight:
errorCode: 200
routers:
my-router:
rule: Host(`localhost`)
middlewares:
- corspreflight-middleware
service: my-service
services:
my-service:
loadBalancer:
servers:
- url: 'http://127.0.0.1'
[http.middlewares]
[http.middlewares.corspreflight-middleware.plugin.corspreflight]
errorCode = 200
[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"

Kubernetes

---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: corspreflight-middleware
spec:
plugin:
corspreflight:
errorCode: 200
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: whoami
spec:
entryPoints:
- web
routes:
- kind: Rule
match: Host(`whoami.localhost`)
middlewares:
- name: corspreflight-middleware
services:
- kind: Service
name: whoami-svc
port: 80
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: corspreflight-middleware
spec:
plugin:
corspreflight:
errorCode: 200
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: myingress
annotations:
traefik.ingress.kubernetes.io/router.middlewares: default-corspreflight-middleware@kubernetescrd
spec:
rules:
- host: whoami.localhost
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: whoami
port:
number: 80

Docker

version: '3.7'
services:
whoami:
image: traefik/whoami:v1.7.1
labels:
traefik.enable: 'true'
traefik.http.routers.app.rule: Host(`whoami.localhost`)
traefik.http.routers.app.entrypoints: websecure
traefik.http.routers.app.middlewares: corspreflight-middleware
traefik.http.middlewares.corspreflight-middleware.plugin.corspreflight.errorcode: 200

Developed & Maintained by

Mehdi Youb

License

License