【问题标题】:SPDY http2 + push throws exception in Angular 6 SSRSPDY http2 + push 在 Angular 6 SSR 中引发异常
【发布时间】:2018-12-27 09:05:07
【问题描述】:

我有一个启用了 SPDY http2 推送和 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: '==' } 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 性能下降之后放置它。

我应该做些什么不同的事情?

【问题讨论】:

    标签: push angular6 http2 spdy server-side-rendering


    【解决方案1】:

    我已经解决了这个问题。这是一些错误和快速修复是:

    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。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-20
      • 2021-06-06
      • 2016-11-13
      • 2015-04-21
      • 2013-10-13
      • 2018-04-05
      • 2018-12-03
      • 2015-01-28
      相关资源
      最近更新 更多