Repository URL to install this package:
|
Version:
1.7.2-rc.1 ▾
|
/**
* If the response contains 'set-cookie' headers, this method duplicates them so that they are also set on the
* local proxying domain. The local domain is localhost by default.
* @param {string} localDomain The domain in which to set the cookies
* @param {Response} response The response coming from the proxied endpoint
*/
export const extendSetCookieHeadersForLocalDomain = (localDomain = 'localhost', response) => {
const cookieSetterHeaders = response.headers['set-cookie'];
if (Array.isArray(cookieSetterHeaders)) {
// If not on localhost, prepend the domain with the `.` so it works on subdomains too
const overriddenDomain = localDomain === 'localhost' ? localDomain : `.${localDomain}`;
cookieSetterHeaders.forEach(header => {
const cookieForLocalhost = header.replace(/Domain=.+?;/, `Domain=${overriddenDomain};`);
cookieSetterHeaders.push(cookieForLocalhost);
});
}
};