ensure version string replacement does not invalidate content length
This commit is contained in:
parent
aa832ae475
commit
49b8b28a51
2 changed files with 11 additions and 4 deletions
11
app.js
11
app.js
|
|
@ -831,13 +831,20 @@ function rewriteHtmlVersion(req, res, next) {
|
|||
if (["/kiri/","/mesh/","/meta/"].indexOf(req.app.path) >= 0) {
|
||||
let real_write = res.write;
|
||||
let real_end = res.end;
|
||||
let mlen = '{{version}}'.length;
|
||||
let vstr = version;
|
||||
if (vstr.length < mlen) {
|
||||
vstr = vstr.padStart(mlen,0);
|
||||
} else if (vstr.length > mlen) {
|
||||
vstr = vstr.substring(0,mlen);
|
||||
}
|
||||
res.write = function() {
|
||||
arguments[0] = arguments[0].toString().replace(/{{version}}/g,version);
|
||||
arguments[0] = arguments[0].toString().replace(/{{version}}/g,vstr);
|
||||
real_write.apply(res, arguments);
|
||||
};
|
||||
res.end = function() {
|
||||
if (arguments[0]) {
|
||||
arguments[0] = arguments[0].toString().replace(/{{version}}/g,version);
|
||||
arguments[0] = arguments[0].toString().replace(/{{version}}/g,vstr);
|
||||
}
|
||||
real_end.apply(res, arguments);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@
|
|||
<title>Meta:Moto</title>
|
||||
<link rel="icon" href="/meta/favicon.ico">
|
||||
<link rel="apple-touch-icon" href="/meta/favicon-mobile.png">
|
||||
<link rel="stylesheet" type="text/css" href="/meta/index.css">
|
||||
<link rel="stylesheet" type="text/css" href="/meta/index.css?{{version}}">
|
||||
<link href="/font/css/all.min.css" rel="stylesheet">
|
||||
<script src="/font/js/all.min.js" crossorigin="anonymous"></script>
|
||||
<script src="/code/meta.js"></script>
|
||||
<script src="/code/meta.js?{{version}}"></script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
|
|
|
|||
Loading…
Reference in a new issue