@lomray/microservice-gateway
Version:
Gateway microservice based on NodeJS & inverted json.
22 lines (18 loc) • 695 B
JavaScript
;
var tslib = require('tslib');
var defaultCors = require('cors');
var remote = require('../config/remote.js');
/**
* Create cors middleware
*/
const cors = (options = {}) => tslib.__awaiter(void 0, void 0, void 0, function* () {
const { corsOptions } = yield remote();
// Check origin's and find regex
if (Array.isArray(corsOptions.origin)) {
corsOptions.origin = corsOptions.origin.map((origin) =>
// if string is regex, convert to regex instance
origin.startsWith('/') ? new RegExp(origin.replace(/^\/|\/$/g, '')) : origin);
}
return defaultCors(Object.assign(Object.assign({}, corsOptions), options));
});
module.exports = cors;