Node.js Express https 服务器崩溃:create 不是函数

问题描述

我正在 Express 环境中构建 Node.js Web API 服务器。当我使用 Greenlock 创建 SSL 证书时,我使用以下代码

require("greenlock-express")
    .create({
        server: "https://acme-staging-v02.api.letsencrypt.org/directory",email: "***@gmail.com",// The email address of the Acme user / 
        agreetos: true,// You must accept the ToS as the host which handles the certs
        configDir: "~/.config/acme/",store: require('greenlock-store-fs'),approveDomains: ['web*****.club'],app: require("../dist/app.js"),debug: true
    })
    .listen(80,443);

在使用 npm start prod 启动服务器后,服务器立即崩溃并产生以下输出

.create({
 ^

TypeError: require(...).create is not a function

当然我安装了 greenlock-express@v4。我还创建了目录 ~/.config/acme

有人知道如何解决这个问题吗?

--

(编辑)

已经尝试过 init() 而不是 create(),使用以下代码

var app = require("../dist/app.js");

    require('greenlock-express').init({
        // Let's Encrypt v2 is Acme draft 11
        version: 'draft-11',server: 'https://acme-v02.api.letsencrypt.org/directory',maintainerEmail: '***@gmail.com',packageRoot: './',configDir: '~/.config/acme/'
      })    // Serves on 80 and 443
      .serve(app);

服务器运行但在第一次请求时崩溃

Error cert_issue:
read ECONNRESET
code: ECONNRESET
Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:209:20)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)