update cookie handling, process saved state and defaults

This commit is contained in:
Stewart Allen 2020-11-20 09:46:10 -05:00
commit 758cee8d46
3 changed files with 23 additions and 20 deletions

13
app.js
View file

@ -62,14 +62,15 @@ function init(mod) {
mod.on.reload(() => level.close());
mod.on.test((req) => {
let vmatch = mod.meta.version || undefined;
let strict = (vmatch && mod.vmatch !== "*") ? true : false;
let cookie = cookieValue(req.headers.cookie, "version") || undefined;
if (strict) {
return cookie === mod.meta.version;
} else {
return (!vmatch && !cookie) || (vmatch && cookie);
let vmatch = mod.meta.version || "*";
if (!Array.isArray(vmatch)) {
vmatch = [ vmatch ];
}
if (vmatch.indexOf("*") >= 0) {
return true;
}
return vmatch.indexOf(cookie) >= 0;
});
mod.add(handleOptions);