@frontegg/client
Advanced tools
Comparing version 1.2.9 to 1.2.10
@@ -41,6 +41,6 @@ "use strict"; | ||
var logger_1 = require("../helpers/logger"); | ||
var getPackageJSON_1 = require("../utils/getPackageJSON"); | ||
var ContextHolder_1 = require("./ContextHolder"); | ||
var FronteggRoutes_1 = require("./FronteggRoutes"); | ||
var utils_1 = require("./utils"); | ||
var getPackageJSON_1 = require("../utils/getPackageJSON"); | ||
var proxy = httpProxy.createProxyServer({ secure: false, changeOrigin: true }); | ||
@@ -66,3 +66,3 @@ var target = process.env.FRONTEGG_API_GATEWAY_URL || 'https://api.frontegg.com/'; | ||
'frontegg-vendor-host': req.hostname, | ||
'frontegg-middleware-client': "Node.js@" + pjson.version | ||
'frontegg-middleware-client': "Node.js@" + pjson.version, | ||
}, | ||
@@ -118,40 +118,23 @@ })]; | ||
proxy.on('proxyRes', function (proxyRes, req, res) { return __awaiter(_this, void 0, void 0, function () { | ||
var context, host_1; | ||
var host_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
logger_1.default.debug("proxyRes - returned for " + req.originalUrl); | ||
if (!options.disableCors) { | ||
utils_1.enableCors(req, proxyRes); | ||
logger_1.default.debug("proxyRes - returned for " + req.originalUrl); | ||
if (!options.disableCors) { | ||
utils_1.enableCors(req, proxyRes); | ||
} | ||
else { | ||
delete proxyRes.headers['access-control-allow-methods']; | ||
delete proxyRes.headers['access-control-allow-headers']; | ||
delete proxyRes.headers['access-control-allow-origin']; | ||
delete proxyRes.headers['access-control-allow-credentials']; | ||
} | ||
if (options.cookieDomainRewrite) { | ||
host_1 = req.headers.host; | ||
Object.keys(proxyRes.headers).forEach(function (key) { | ||
if (key.toLowerCase() === 'set-cookie') { | ||
proxyRes.headers[key] = utils_1.rewriteCookieDomain(proxyRes.headers[key], host_1, options.cookieDomainRewrite); | ||
} | ||
else { | ||
delete proxyRes.headers['access-control-allow-methods']; | ||
delete proxyRes.headers['access-control-allow-headers']; | ||
delete proxyRes.headers['access-control-allow-origin']; | ||
delete proxyRes.headers['access-control-allow-credentials']; | ||
} | ||
if (!(proxyRes.statusCode === 401)) return [3 /*break*/, 3]; | ||
req.frontegg.retryCount = req.frontegg.retryCount + 1; | ||
logger_1.default.log(req.url + " failed with authentication error from proxy - retryCount - ", req.frontegg.retryCount); | ||
if (!(req.frontegg.retryCount <= MAX_RETRIES)) return [3 /*break*/, 3]; | ||
logger_1.default.warn('going to refresh authentication'); | ||
return [4 /*yield*/, authenticator.refreshAuthentication()]; | ||
case 1: | ||
_a.sent(); | ||
logger_1.default.warn('refreshed authentication'); | ||
return [4 /*yield*/, options.contextResolver(req)]; | ||
case 2: | ||
context = _a.sent(); | ||
return [2 /*return*/, proxyRequest(req, res, context)]; | ||
case 3: | ||
if (options.cookieDomainRewrite) { | ||
host_1 = req.headers.host; | ||
Object.keys(proxyRes.headers).forEach(function (key) { | ||
if (key.toLowerCase() === 'set-cookie') { | ||
proxyRes.headers[key] = utils_1.rewriteCookieDomain(proxyRes.headers[key], host_1, options.cookieDomainRewrite); | ||
} | ||
}); | ||
} | ||
return [2 /*return*/]; | ||
}); | ||
} | ||
return [2 /*return*/]; | ||
}); | ||
@@ -158,0 +141,0 @@ }); }); |
{ | ||
"name": "@frontegg/client", | ||
"version": "1.2.9", | ||
"version": "1.2.10", | ||
"description": "Frontegg Javascript Library for backend", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
246086
3665