我在节点中设置了自己的Restify服务器来提供HTML:
const ServeHTML = (folder: string, page: string, res: Restify.Response, data: Object) => {
let path:string = __dirname+"/../../"+folder+page;
let MimeType: string | null = Mime.getType(path);
if(!MimeType) MimeType = "";
let body:string = fs.readFileSync(path, "utf8");
res.writeHead(200, {
'Content-Length': Buffer.byteLength(body, "utf8"),
'Content-Type': MimeType
});
Object.keys(data).forEach(function(key,index) {
let regex = new RegExp("{{"+key+"}}", 'gi');
body = body.replace(regex, (<any>data)[key]);
});
res.write(body);
res.end();
}
如您所见,我已经在计算Content-Length。但是,我仍然收到错误:
GET http://localhost:4000/WebChat net::ERR_CONTENT_LENGTH_MISMATCH 200 (OK)
我在做什么错了?