Tree Gateway - Cors

Cors

Cors Example --- name: MyCorsTestAPI version: 1.0.0 path: cors/ proxy: target: host: http://httpbin.org cors: origin: enableAll: true

This sample enables cors requests from all origins.

Cors Origins

Cors Origins Example --- name: MyCorsTestAPI version: 1.0.0 path: cors/ proxy: target: host: http://httpbin.org cors: origin: allow: - value: http://example1.com - value: http://example2.com methods: - GET - PUT - POST allowedHeaders: - X-MyHeader

This sample enables cors requests from a specific set of origins and HTTP methods and allow access to a specific header.

Cors Origins Regexp

Cors Origins Regexp Example --- name: MyCorsTestAPI version: 1.0.0 path: cors/ proxy: target: host: http://httpbin.org cors: origin: allow: regexp: "/example\\.com$/"

This sample enables cors requests depending on the origin. It uses a regular expression to check the origin.

Cors Origins Middleware

Cors Origins Middleware Example --- name: MyCorsTestAPI version: 1.0.0 path: cors/ proxy: target: host: http://httpbin.org cors: origin: middleware: name: myCorsCheck const whiteList = ['http://example1.com']; module.exports = function (origin) { return (whitelist.indexOf(origin) !== -1); };

This sample enables cors requests depending on the origin. It uses a custom middleware to check the origin.