browsersync + http2 +压缩https:// localhost

时间:2017-10-13 15:11:30

标签: node.js gulp gzip browser-sync http2

尝试使用https,http2和gzip初始化browserync,但似乎永远不能让它们全部很好地一起玩

var gulp         = require('gulp');
var browserSync  = require('browser-sync');
var compression  = require('compression');

gulp.task('browser-sync', function() {
    browserSync.init({
        server: {
            baseDir: "dist",
            middleware: [compression()]
        },
        httpModule: 'http2',
        https: {
            key: "/path/to/localhost.key",
            cert: "/path/to/localhost.crt"
        }
    })
})

我可以让http2在没有压缩的情况下工作,压缩在没有http2的情况下工作,但从不同时工作......我得到的错误是

Error: Can't set headers after they are sent.

使用快递做同样的事情是成功的

var express      = require('express');
var http2        = require('spdy');
var serveStatic  = require('serve-static');
var compression  = require('compression');

var credentials = {
    key: "/path/to/localhost.key",
    cert: "/path/to/localhost.crt"
};
var app = express();
app.use(compression())
app.use(serveStatic('./dist', {
    'extensions': ['html'],
    'maxAge': 3600000
}))
var httpsServer = http2.createServer(credentials, app);
httpsServer.listen(8888);

但使用browsersync

并不高兴

任何帮助,非常感谢。

0 个答案:

没有答案