-
Notifications
You must be signed in to change notification settings - Fork 43
Cors Handler
thiagobustamante edited this page Jun 15, 2017
·
4 revisions
A Cors middleware is a function that receives the request origin from the gateway and must return a boolean value (or a Promise) to inform if the given origin is allowed.
Each filter must be defined on its own .js file.
Example:
/**
* @param origin the origin extracted from request.
*/
module.exports = function (origin) {
return (whitelist.indexOf(origin) !== -1);
};
or, using Promises:
module.exports = function (origin) {
return new Promise((resolve, reject) => {
setTimeout(function(){resolve(whitelist.indexOf(origin) !== -1);}, 10);
});
};
You can configure a cors middleware through:
- Admin Rest API:
POST /cors
- SDK:
sdk.middleware.addCors(name, fileName);
- CLI:
treeGatewayConfig middleware cors -a <name> ./filename.js