diff --git a/lib/dashboards.js b/lib/dashboards.js index f4a93e4..3d05cf1 100644 --- a/lib/dashboards.js +++ b/lib/dashboards.js @@ -34,7 +34,7 @@ exports.detectLocal = function () { }; exports.readCookie = function () { - var value = cookies.readBrowserCookie('_dashboard_urls'); + var value = cookies.readCookie('_dashboard_urls'); if (value) { var durls = JSON.parse(unescape(value)); exports._dashboard_urls = _.uniq(exports._dashboard_urls.concat(durls)); @@ -45,7 +45,7 @@ exports.updateCookie = function () { cookies.setBrowserCookie(null, { name: '_dashboard_urls', value: JSON.stringify(exports._dashboard_urls), - path: dutils.getBaseURL() + path: '/' }); }; diff --git a/packages/cookies/cookies.js b/packages/cookies/cookies.js index f651923..05f3abb 100644 --- a/packages/cookies/cookies.js +++ b/packages/cookies/cookies.js @@ -34,6 +34,18 @@ exports.readBrowserCookies = function () { return cookies; }; +exports.readCookie = function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for (var i = 0; i < ca.length; i++) { + var c = ca[i]; + while (c.charAt(0) == ' ') c = c.substring(1, c.length); + if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); + } + return null; +} + + /** * Reads browser cookies and returned the value of the named cookie. * @@ -81,7 +93,6 @@ exports.setBrowserCookie = function (req, opt) { throw new Error('setBrowserCookie cannot be called server-side'); } var str = (typeof opt === 'string') ? opt: exports.cookieString(req, opt); - //console.log('document.cookie = ' + str); document.cookie = str; };