From e3ed2488e81b3a78124cff531258ca6c8e792d7e Mon Sep 17 00:00:00 2001 From: Taylor Helsper Date: Tue, 16 Jun 2020 22:43:56 -0500 Subject: [PATCH] Add HTTPS option --- bin/corsproxy | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bin/corsproxy b/bin/corsproxy index 64a5ab5..caf04cc 100755 --- a/bin/corsproxy +++ b/bin/corsproxy @@ -4,13 +4,22 @@ var Hapi = require('hapi') var plugin = require('../index') var good = require('good') var loggerOptions = require('../lib/logger-options') +var fs = require('file-system') var server = new Hapi.Server({}) var port = parseInt(process.env.CORSPROXY_PORT || process.env.PORT || 1337, 10) var host = (process.env.CORSPROXY_HOST || 'localhost'); var target = (process.env.CORSPROXY_TARGET || null); var maxPayload = parseInt(process.env.CORSPROXY_MAX_PAYLOAD || 1048576, 10) -var proxy = server.connection({ port: port, labels: ['proxy'], host: host}) +var options = {port: port, labels: ['proxy'], host: host} +if (process.env.CORSPROXY_USE_HTTPS) { + var tls = { + key: fs.readFileSync(process.env.CORSPROXY_HTTPS_KEY), + cert: fs.readFileSync(process.env.CORSPROXY_HTTPS_CERT) + }; + options = {port: port, labels: ['proxy'], tls: tls, host: host} +} +var proxy = server.connection(options) server.register(require('inert'), function () {}) server.register(require('h2o2'), function () {})