[英]SPDY http2 + push throws exception in Angular 6 SSR
我有啟用SPDY http2 push和SSR的Angular 6項目。 當用力刷新單擊更多內容並四處瀏覽時,有時會出現以下錯誤:
在刷新幾下之后,我得到了一個奇怪的錯誤: { AssertionError [ERR_ASSERTION]: false == true at PriorityNode.removeChild (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:130338:3) at PriorityNode.remove (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:130326:15) at PriorityTree.add (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:130427:23) at Stream._initPriority (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:130559:25) at new Stream (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:130534:8) at Connection._createStream (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:131564:16) at Connection._handleHeaders (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:131612:21) at Connection._handleFrame (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:131495:10) at Parser.<anonymous> (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:131332:10) at ZoneDelegate.invokeTask (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:117435:31) generatedMessage: true, name: 'AssertionError [ERR_ASSERTION]', code: 'ERR_ASSERTION', actual: false, expected: true, operator: '==' }
{ AssertionError [ERR_ASSERTION]: false == true at PriorityNode.removeChild (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:130338:3) at PriorityNode.remove (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:130326:15) at PriorityTree.add (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:130427:23) at Stream._initPriority (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:130559:25) at new Stream (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:130534:8) at Connection._createStream (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:131564:16) at Connection._handleHeaders (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:131612:21) at Connection._handleFrame (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:131495:10) at Parser.<anonymous> (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:131332:10) at ZoneDelegate.invokeTask (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:117435:31) generatedMessage: true, name: 'AssertionError [ERR_ASSERTION]', code: 'ERR_ASSERTION', actual: false, expected: true, operator: '==' }
TypeError: Cannot read property 'getPriority' of null at C:\\git\\wearlenses-3-client\\web\\dist\\server.js:130627:32 at ZoneDelegate.invokeTask (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:117435:31) at Zone.runTask (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:117202:47) at ZoneTask.invokeTask (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:117510:34) at ZoneTask.invoke (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:117499:48) at data.args.(anonymous function) (C:\\git\\wearlenses-3-client\\web\\dist\\server.js:118352:25) at process._tickCallback (internal/process/next_tick.js:112:11)
這是部分代碼:
```app.get('*',(req:any,res:any)=> {
try {
Promise.all([...config.files]).then((data: any[]) => {
for (let i = 0; i < config.files.length; i++) {
const pushOptions = {
status: 200, // optional
method: 'GET', // optional
request: {
accept: '*/*'
},
response: {
'content-type': config.files[i].mimeType,
'Cache-Control': 'public, max-age=30672000'
}
};
let contentToSend = data[i];
if (config.files[i].mimeType === 'application/font-woff2') {
contentToSend = new Buffer(contentToSend);
pushOptions.response['Content-Length'] = contentToSend.length;
pushOptions.response['Accept-Ranges'] = 'bytes';
}
if (config.files[i].gzip) {
pushOptions.response['content-encoding'] = 'gzip';
contentToSend = zlib.gzipSync(contentToSend);
}
const stream = (<any>res).push(`/${config.files[i].name}`, pushOptions);
stream.on('error', () => { });
stream.end(contentToSend);
}
}).catch(error => { });
} catch (e) {
console.log(e);
}
res.render('index', { req });
}); ```
我覺得應該在另一個地方有res.render,但是如果我嘗試在stream.end
性能下降之后放它。
我應該做些什么?
我已經解決了這個問題。 這是一些錯誤,快速修復方法是:
let fs = require('fs')
let path = require('path')
let file = path.join(
process.cwd(),
'node_modules/spdy-transport/lib/spdy-transport/priority.js'
)
let data = fs
.readFileSync(file)
.toString()
.split('\n')
if (data.length < 190) {
data.splice(73, 0, '/*')
data.splice(75, 0, '*/')
data.splice(
187,
0,
`
var index = utils.binarySearch(this.list, node, compareChildren);
this.list.splice(index, 1);
`
)
let text = data.join('\n')
fs.writeFile(file, text, function(err) {
if (err) return console.log(err)
})
}
資料來源:
https://github.com/spdy-http2/spdy-transport/issues/47
https://github.com/Noumenae/server/issues/20
https://github.com/spdy-http2/node-spdy/issues/285
https://github.com/spdy-http2/node-spdy/issues/244
據我了解,每個人都在等待Express 5,它將獲得natvie http2支持。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.