Skip to content

Commit

Permalink
✨ feat [CLI]: --cert ./cert.pem & --privkey ./priv.pem #2812
Browse files Browse the repository at this point in the history
  • Loading branch information
smashah committed Aug 16, 2022
1 parent 5d3be9e commit 287e389
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/cli/cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,17 @@ Merge<Merge<{
description: "Offload the EASY API to local instance of pm2. You can add pm2 specific arguments also if you want."
},
{
name: 'privkey',
type: String,
typeLabel: '{yellow {underline "./privatekey.pem"}}',
description: "The private key to use for the TLS connection. --cert is also required"
},
{
name: 'cert',
type: String,
typeLabel: '{yellow {underline "./certificate.pem"}}',
description: "The certificate to use for the TLS connection. --privkey is also required"
},
{
name: 'helmet',
type: Boolean,
Expand Down
15 changes: 14 additions & 1 deletion src/cli/server.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//@ts-ignore
import express from 'express';
import http from 'http';
import http, { ServerOptions } from 'http';
import { collections } from './collections';
import robots from "express-robots-txt";
import swaggerUi from 'swagger-ui-express';
import { default as axios } from 'axios'
import parseFunction from 'parse-function';
import { Client, ev, SimpleListener, ChatId, Message, log } from '..';
import qs from 'qs';
import * as fs from 'fs';
import { convert } from 'xmlbuilder2';
import { chatwootMiddleware, setupChatwootOutgoingMessageHandler } from './integrations/chatwoot';
import {IpFilter} from'express-ipfilter'
Expand Down Expand Up @@ -44,6 +45,18 @@ export const setupHttpServer = (cliConfig: cliFlags) => {
//@ts-ignore
app.use(helmet())
}
const privkey = `${process.env.PRIV || cliConfig.privkey || ""}`;
const cert = `${process.env.CERT || cliConfig.cert || ""}`;
if(privkey && cert) {
const privContents = fs.readFileSync(privkey);
const certContents = fs.readFileSync(cert);
if(privContents && certContents) {
const options = {key: privContents,cert: certContents}
server = http.createServer(options as ServerOptions, app);
return;
}
}
server = http.createServer(app);
}

export const setUpExpressApp : () => void = () => {
Expand Down

0 comments on commit 287e389

Please sign in to comment.