一个自动集成https证书, http/https请求自动转发到内网真实服务的工具
使用
import forward from "@ai-lion/cert-forward";
import http from "http";
import https from "https";
forward({
subject: "xxxx.com",//根域名
altnames: ["www.xxxx.com", "api.xxxx.com"],// 子域名
port: 80,//绑定的端口, 对外网开放的商品, http和https共用一个端口
}, ({ ward, key, cert }) => {
let httpServer = http.createServer();
httpServer.listen(0, "127.0.0.1", () => {
let address = server.address();
console.info("http listen", address);
ward.httpPort = address.port; //转发的 http服务 端口
// ward.httpHost = "127.0.0.1";// 转发的 http服务 ip 默认127.0.0.1
});
let httpsServer = https.createServer(
{
key: key,
cert: cert,
}
);
httpsServer.listen(0, "127.0.0.1", () => {
let address = server.address();
console.info("http listen", address);
ward.httpsPort = address.port; //转发的 http服务 端口
// ward.httpsHost = "127.0.0.1";// 转发的 http服务 ip 默认127.0.0.1
});
});