Closed mrpinkcat closed 5 years ago
I have extend the BootBot class for https server.
class HttpsBootBot extends BootBot {
constructor(option) {
super(option);
}
startHttps(credentials, port) {
console.log('BOT Https');
this.httpsServer = https_1.default.createServer(credentials, this.app);
this.start(port);
}
start(port) {
this._initWebhook();
this.app.set('port', port || 3000);
if (this.httpsServer) {
this.httpsServer.listen(this.app.get('port'), () => {
const portNum = this.app.get('port');
console.log('BootBot running on port', portNum);
console.log(`Facebook Webhook running on localhost:${portNum}${this.webhook}`);
});
}
else {
console.log('error extend bootbot start');
}
}
close() {
if (this.httpsServer) {
this.httpsServer.close();
}
else {
console.log('error extend bootbot stop');
}
}
}
Insted of call new BootBot(...).start(port)
you can now call startHttps
e.g.
const privateKey = fs.readFileSync(env_1.config.tls.key, 'utf8');
const certificate = fs.readFileSync(env_1.config.tls.cert, 'utf8');
const credentials = { key: privateKey, cert: certificate };
new HttpsBootBot(...).startHttps(credentials, port);
Hey @mrpinkcat, I think that's a solid solution. Thanks for sharing!
If you'd like to add the option to BootBot itself, feel free to open a PR and tag me on it.
Can I use https server with certificate insted express http server ? @Charca