feat: allow custom locale store cookie domain (#33)

* test: use mocha@4
This commit is contained in:
fengmk2
2019-04-17 10:43:00 +08:00
committed by GitHub
parent b3c8ab19e5
commit 08037ee0ae
6 changed files with 50 additions and 12 deletions

View File

@@ -27,6 +27,7 @@ module.exports = function (app, options) {
const defaultLocale = formatLocale(options.defaultLocale);
const queryField = options.queryField;
const cookieField = options.cookieField;
const cookieDomain = options.cookieDomain;
const localeAlias = options.localeAlias;
const writeCookie = options.writeCookie;
const cookieMaxAge = ms(options.cookieMaxAge);
@@ -194,12 +195,14 @@ module.exports = function (app, options) {
// if header not send, set the locale cookie
if (writeCookie && cookieLocale !== locale && !this.headerSent) {
// locale change, need to set cookie
this.cookies.set(cookieField, locale, {
const cookieOptions = {
// make sure brower javascript can read the cookie
httpOnly: false,
maxAge: cookieMaxAge,
signed: false,
});
domain: cookieDomain,
};
this.cookies.set(cookieField, locale, cookieOptions);
debugSilly('Saved cookie with locale %s', locale);
}
debug('Locale: %s from %s', locale, localeOrigin);