From 8f35aaef1183d9216ab1fd780dcc142eb2201c65 Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Fri, 23 Jul 2021 13:31:01 -0600 Subject: [PATCH] feature: allow non-secure connections - default to secure - parameterize via env var --- build/Dockerfile | 1 + build/entrypoint.sh | 15 +++++++++++++++ build/livereload.js | 13 ++++++++----- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/build/Dockerfile b/build/Dockerfile index 9c94e12..7944526 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -39,6 +39,7 @@ ENV LR_EXTS="html,xml,css,js,jsx,ts,tsx,php,py" ENV LR_EXCLUDE=".git/,.svn/,.vscode/,.idea/" ENV LR_DELAY=500 ENV LR_DEBUG=true +ENV LR_HTTPS=true # install livereload npm as node user then switch back to root user USER node diff --git a/build/entrypoint.sh b/build/entrypoint.sh index 081a9f2..7efafcb 100644 --- a/build/entrypoint.sh +++ b/build/entrypoint.sh @@ -6,21 +6,36 @@ # functions certificateGenerateNew() { + certificateCheckEnabled printf "\nGenerating new self-signed certificate:\n" printf "Exporting new certificate:\n" exit 0 } certificateShow() { + certificateCheckEnabled printf "\nCurrently loaded certificate:\n" exit 0 } certificateExport() { + certificateCheckEnabled printf "\nExporting currently loaded certificate:\n" exit 0 } +certificateCheckEnabled() { + httpsEnabled="$(convertCaseUpper "$LR_HTTPS")" + if [ "$httpsEnabled" != "TRUE" ]; then + printf "\nSSL/TLS not enabled. Please set LR_HTTPS=TRUE if you want to enable SSL/TLS.\n" + exit 1 + fi +} + +convertCaseUpper() { + printf "%s" "$1" | tr "[:lower:]" "[:upper:]" +} + # default variable values doCertExport=0 doCertNew=0 diff --git a/build/livereload.js b/build/livereload.js index 94a11f1..5489be9 100644 --- a/build/livereload.js +++ b/build/livereload.js @@ -4,13 +4,8 @@ let livereload = require('livereload'); // set createServer options -const https = require('https'); const fs = require('fs'); const options = { - https: { - cert: fs.readFileSync('/certs/fullchain.pem'), - key: fs.readFileSync('/certs/privkey.pem') - }, port: process.env.LR_PORT, exts: process.env.LR_EXTS, exclusions: process.env.LR_EXCLUDE, @@ -19,6 +14,14 @@ const options = { debug: process.env.LR_DEBUG }; +if (process.env.LR_HTTPS) { + options.https = { + cert: fs.readFileSync('/certs/fullchain.pem'), + key: fs.readFileSync('/certs/privkey.pem') + + }; +} + // start server let server = livereload.createServer(options); server.watch('/watch')