Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Https server ? #182

Closed
mrpinkcat opened this issue Sep 10, 2019 · 2 comments
Closed

Https server ? #182

mrpinkcat opened this issue Sep 10, 2019 · 2 comments

Comments

@mrpinkcat
Copy link

Can I use https server with certificate insted express http server ? @Charca

@mrpinkcat
Copy link
Author

mrpinkcat commented Sep 11, 2019

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);

@Charca
Copy link
Owner

Charca commented Sep 11, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants