节点 JS 上通过 HTTPS 的 LiveReload 将不起作用

LiveReload over HTTPS on node JS will not work

在我不得不更改为 https 之前,它一直运行良好。 这是我的 livereload 配置:

const express = require("express");
const app = express();
const path = require('path');
const livereload = require('livereload')
const connectLiveReload = require('connect-livereload')


const liveReloadServer = livereload.createServer();
liveReloadServer.watch(publicDirectory)
liveReloadServer.server.once("connection",()=>{
    setTimeout(() => {
        liveReloadServer.refresh("/");
    }, 200);
})

app.use(connectLiveReload());

它开始显示的错误是:

当然,它不会接受更改和重新加载。

来自包 livereload 的 npm 页面 here

Server API

The createServer() method accepts two arguments.

The first are some configuration options, passed as a JavaScript object:

  • https is an optional object of options to be passed to https.createServer (if not provided, http.createServer is used instead)

你可以查看有关 https.createServer here

的 NodeJS 文档

据此,我认为 liveReloadServer 的配置应该是这样的,您使用您的 SSL 证书和密钥 :

const liveReloadServer = livereload.createServer({
    https : {
        key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
        cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
    }
});