add code refresh when source changes
This commit is contained in:
parent
127c0451c5
commit
6dbff53922
1 changed files with 22 additions and 4 deletions
|
|
@ -317,16 +317,14 @@ function setup(req, res, next) {
|
||||||
if (rec.saved === 0) {
|
if (rec.saved === 0) {
|
||||||
ipCache[ipaddr] = rec;
|
ipCache[ipaddr] = rec;
|
||||||
if (!rec.host) {
|
if (!rec.host) {
|
||||||
// prevent overlapping lookups
|
// prevent overlapping lookups for the same address
|
||||||
// for the same address
|
|
||||||
rec.host = 'unknown';
|
rec.host = 'unknown';
|
||||||
try {
|
try {
|
||||||
dns.reverse(ipaddr, (err,addr) => {
|
dns.reverse(ipaddr, (err,addr) => {
|
||||||
rec.host = addr;
|
rec.host = addr;
|
||||||
// if (addr) log({ip:ipaddr, addr:addr});
|
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
helper.log({dns_err: e, ipaddr})
|
helper.log({dns_err: ipaddr})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -594,11 +592,25 @@ function handleJS(req, res, next) {
|
||||||
function handleCode(req, res, next) {
|
function handleCode(req, res, next) {
|
||||||
let cookie = getCookieValue(req.headers.cookie),
|
let cookie = getCookieValue(req.headers.cookie),
|
||||||
key = req.gs.path.split('/')[2].split('.')[0],
|
key = req.gs.path.split('/')[2].split('.')[0],
|
||||||
|
ck = code_src[key],
|
||||||
js = code[key];
|
js = code[key];
|
||||||
|
|
||||||
if (!js) {
|
if (!js) {
|
||||||
return reply404(req, res);
|
return reply404(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ck) {
|
||||||
|
let mod = lastmod(ck.path);
|
||||||
|
if (mod > ck.mod) {
|
||||||
|
if (debug) {
|
||||||
|
js = code[ck.endpoint] = fs.readFileSync(ck.path);
|
||||||
|
} else {
|
||||||
|
js = code[ck.endpoint] = minify(ck.path);
|
||||||
|
}
|
||||||
|
ck.mod = mod;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
addCorsHeaders(req, res);
|
addCorsHeaders(req, res);
|
||||||
serveCode(req, res, {
|
serveCode(req, res, {
|
||||||
code: js,
|
code: js,
|
||||||
|
|
@ -845,6 +857,7 @@ let ver = require('../js/license.js'),
|
||||||
"kiri-worker"
|
"kiri-worker"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
code_src = {},
|
||||||
code = {},
|
code = {},
|
||||||
inject = {},
|
inject = {},
|
||||||
injectKeys = ["kiri", "meta"],
|
injectKeys = ["kiri", "meta"],
|
||||||
|
|
@ -1040,6 +1053,11 @@ function initModule(file, dir) {
|
||||||
} else {
|
} else {
|
||||||
code[endpoint] = minify(path);
|
code[endpoint] = minify(path);
|
||||||
}
|
}
|
||||||
|
code_src[endpoint] = {
|
||||||
|
endpoint,
|
||||||
|
path,
|
||||||
|
mod: lastmod(path)
|
||||||
|
};
|
||||||
},
|
},
|
||||||
redir: redir,
|
redir: redir,
|
||||||
remap: remap
|
remap: remap
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue