首页 > 解决方案 > https.createServer 不工作 REST 服务器

问题描述

我正在尝试使用 express 和 typescript 创建一个 HTTPS 服务器,这是我的代码,由于某种原因 https.createserver 似乎永远无法正常工作,我收到此错误:

UnhandledPromiseRejectionWarning: E​​rror: error:0909006C:PEM routines:get_name:no start line

但我是新手,我在网上找到了 0 个答案。

在我的构造函数中的 App.ts 上,我有:

this.express= express();
const key = fs.readFileSync('/home/user/private.key');
const cert = fs.readFileSync('/home/user/file.csr');
this.middlewares();
this.routes();
this.app = https.createServer({ key, cert }, this.express);

以及初始化应用程序的函数监听:

listen() {
    this.app.listen(3000);
    console.log('Server on port', 3000);
}

在我的 index.ts 上

import { App } from './app'
import { connect } from './database'

function main() {
    const app = new App(4001);
    app.listen();
}

main();

标签: typescriptexpresssslhttps

解决方案


推荐阅读