Cross Origin Resource Sharing

EnRoute Technical Reference

CORS Plugin

The CORS plugin enables the CORS Envoy filter for EnRoute Ingress Gateway or Standalone Gateway

CORS Filter Configuration

CORS filter configuration needs the following config

FieldDescription
match_conditionMatch condition is one of - ["exact", "prefix", "suffix", "contains", "regex"]
access_control_allow_methodsSpecifies the content for the access-control-allow-methods header
access_control_allow_headersSpecifies the content for the access-control-allow-headers header
access_control_expose_headersSpecifies the content for the access-control-expose-headers header.
access_control_max_ageSpecifies the content for the access-control-max-age header.
CORS Filter Config Example
{
     "match_condition" : {
       "regex" : "\\*"
     },
     "access_control_allow_methods" : "GET, OPTIONS",
     "access_control_allow_headers" : "Content-Type",
     "access_control_expose_headers" : "*",
     "access_control_max_age" : "120"
}

Notes

CORS Filter Config for KubernetesCORS Filter Config for Standalone

---
apiVersion: enroute.saaras.io/v1
kind: HttpFilter
metadata:
  labels:
    app: svc-app
  name: svc-corsfilter
  namespace: svc-namespace
spec:
  name: svc-corsfilter
  type: http_filter_cors
  httpFilterConfig:
    config: |
         {
             "match_condition" : {
               "regex" : "\\*"
             },
             "access_control_allow_methods" : "GET, OPTIONS",
             "access_control_allow_headers" : "Content-Type",
             "access_control_expose_headers" : "*",
             "access_control_max_age" : "120"
         }
---

CORS_FILTER_NAME="svc-corsfilter"
CORS_FILITER_TYPE="http_filter_cors"
CORS_CONFIG='
{
    "match_condition" : {
      "regex" : "\\*"
    },
    "access_control_allow_methods" : "GET, OPTIONS",
    "access_control_allow_headers" : "Content-Type",
    "access_control_expose_headers" : "*",
    "access_control_max_age" : "120"
}
'
curl -s -X POST localhost:1323/filter   \
    -d "filter_name=${CORS_FILTER_NAME}" \
    -d "filter_type=${CORS_FILTER_TYPE}" \
    -d "filter_config"="${CORS_CONFIG}"