Skip to content

SergioFloresG/corsmiddleware

Repository files navigation

Main Matrix

The existing plugins can be browsed into the Plugin Catalog.

Usage

Use this middleware to add CORS support to the necessary endpoints, indicating their domain, allowed methods and more.

Configuration

Requirements: Traefik >= v2.5.5

Option Description Header
allowCredentials This indicates whether or not the actual request can be made using credentials.
(default: false)
Access Control Allow Credentials
allowOrigins Indicates the group of sources that have access to the requesting resource.
(default: *)
Access Control Allow Origin
allowMethods Specifies one or more methods allowed when accessing a resource in response.
(default: OPTIONS, GET, POST, PUT, DELETE)
Access Control Allow Methods
allowHeaders Indicate which HTTP headers can be used during the actual request. the indicated headers are an addition to default ones Access Control Allow Headers
exposeHeaders Indicate which response headers should be made available to scripts running in the browser, in response to a cross-origin request. Access Control Expose Headers
maxAge: Indicates how long the results of a preflight request can be cached
(default: 86400)
Access Control Max Age

Default Allow Headers: Content-Type, Content-Length, Accept-Encoding, Authorization, Accept, Origin, Referer, Cache-Control

Traefik

# Static configuration

experimental:
  plugins:
    example:
      moduleName: github.com/SergioFloresG/corsmiddleware
      version: v0.1.0

Here is an example of a file provider dynamic configuration (given here in YAML), where the interesting part is the http.middlewares section:

# Dynamic configuration

http:
  routers:
    my-router:
      rule: host(`demo.localhost`)
      service: service-foo
      entryPoints:
        - web
      middlewares:
        - my-cors-middleware

  services:
    service-foo:
      loadBalancer:
        servers:
          - url: http://127.0.0.1:5000

  middlewares:
    my-cors-middleware:
      plugin:
        corsmiddleware:
          allowOrigins: ["https://example.com"]