prevent cache collision when switching from debug to live
This commit is contained in:
parent
982ca1a5bc
commit
d6aaa473af
1 changed files with 5 additions and 3 deletions
8
app.js
8
app.js
|
|
@ -25,6 +25,7 @@ let setupFn;
|
||||||
let cacheDir;
|
let cacheDir;
|
||||||
let startTime;
|
let startTime;
|
||||||
let oversion;
|
let oversion;
|
||||||
|
let dversion;
|
||||||
let lastmod;
|
let lastmod;
|
||||||
let logger;
|
let logger;
|
||||||
let debug;
|
let debug;
|
||||||
|
|
@ -43,6 +44,7 @@ function init(mod) {
|
||||||
dir = mod.dir;
|
dir = mod.dir;
|
||||||
log = mod.log;
|
log = mod.log;
|
||||||
|
|
||||||
|
dversion = debug ? `_${version}` : version;
|
||||||
cacheDir = mod.util.datadir("cache");
|
cacheDir = mod.util.datadir("cache");
|
||||||
|
|
||||||
let depcache = {};
|
let depcache = {};
|
||||||
|
|
@ -527,7 +529,7 @@ function handleSetup(req, res, next) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleVersion(req, res, next) {
|
function handleVersion(req, res, next) {
|
||||||
let vstr = oversion || version;
|
let vstr = oversion || dversion || version;
|
||||||
if (["/kiri/","/mesh/","/meta/"].indexOf(req.app.path) >= 0 && req.url.indexOf(vstr) < 0) {
|
if (["/kiri/","/mesh/","/meta/"].indexOf(req.app.path) >= 0 && req.url.indexOf(vstr) < 0) {
|
||||||
if (req.url.indexOf("?") > 0) {
|
if (req.url.indexOf("?") > 0) {
|
||||||
return http.redirect(res, `${req.url},ver:${vstr}`);
|
return http.redirect(res, `${req.url},ver:${vstr}`);
|
||||||
|
|
@ -668,7 +670,7 @@ function concatCode(array) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
const code = [ '(function() { let load = [ ' ];
|
const code = [ '(function() { let load = [ ' ];
|
||||||
direct.forEach(file => {
|
direct.forEach(file => {
|
||||||
const vers = cachever[file] || version;
|
const vers = cachever[file] || dversion || version;
|
||||||
code.push(`"/${file.replace(/\\/g,'/')}?${vers}",`);
|
code.push(`"/${file.replace(/\\/g,'/')}?${vers}",`);
|
||||||
});
|
});
|
||||||
code.push([
|
code.push([
|
||||||
|
|
@ -866,7 +868,7 @@ function rewriteHtmlVersion(req, res, next) {
|
||||||
let real_write = res.write;
|
let real_write = res.write;
|
||||||
let real_end = res.end;
|
let real_end = res.end;
|
||||||
let mlen = '{{version}}'.length;
|
let mlen = '{{version}}'.length;
|
||||||
let vstr = version;
|
let vstr = dversion || version;
|
||||||
if (vstr.length < mlen) {
|
if (vstr.length < mlen) {
|
||||||
vstr = vstr.padStart(mlen,0);
|
vstr = vstr.padStart(mlen,0);
|
||||||
} else if (vstr.length > mlen) {
|
} else if (vstr.length > mlen) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue