我正在 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)