5 Commits

Author SHA1 Message Date
asif 8cafe6e164 fix readme formatting error 2021-07-28 04:24:42 -06:00
asif 99cc14532c docs(readme): update readme to reflect fixed exclusions 2021-07-28 04:20:50 -06:00
asif 13ec1a72e9 style(livereload): format code 2021-07-28 04:12:19 -06:00
asif 1194fc63c6 fix(livereload): fix exclusions bug
- read environment var as array
- convert array elements to regex objects
- update environment variable defaults
2021-07-28 03:51:56 -06:00
asif 574b6e1e07 refactor(dockerfile): update existing packages to latest versions 2021-07-28 03:50:03 -06:00
3 changed files with 21 additions and 13 deletions
+3 -1
View File
@@ -53,7 +53,7 @@ All environment variables have sensible defaults and, thus, are *not* required t
| TZ | Set the container's time zone. NO impact on runtime, included for convenience. | Etc/UTC | | TZ | Set the container's time zone. NO impact on runtime, included for convenience. | Etc/UTC |
| LR_PORT | Port over which Livereload will communicate. All clients presently expect port 35729, so I suggest leaving this alone. | 35729 | | LR_PORT | Port over which Livereload will communicate. All clients presently expect port 35729, so I suggest leaving this alone. | 35729 |
| LR_EXTS | Defines monitored extensions. | html,xml,css,js,jsx,ts,tsx,php,py | | LR_EXTS | Defines monitored extensions. | html,xml,css,js,jsx,ts,tsx,php,py |
| LR_EXCLUDE | Array of JavaScript regular-expressions (Regex) that define paths or files to ignore. These are *appended* to the node-livereload upstream defaults which ignore everything in the `.git/`, `.svn/` and `.hg/` directories.<br />JavaScript regex format is: `/your-regex/`<br />**N.B.** At present, exclusions do not seem to be working properly. Ive filed an issue upstream and will update the container when its resolved. | /\\.vscode//,/\\.idea//,/\\.tmp/,/\\.swp/ | | LR_EXCLUDE | Comma-delimited regular-expressions (Regex) that define paths or files to ignore. These are *appended* to the node-livereload upstream defaults which ignore everything in the `.git/`, `.svn/` and `.hg/` directories.<br />**N.B.** You do *not* have to use JavaScript format. The script will automatically convert things to JS-RegEx. You do, however, need to escape any special characters. | .vscode/,.idea/,.tmp$,.swp$/ |
| LR_DELAY | Time (ms) between polling for changed files. | 500 | | LR_DELAY | Time (ms) between polling for changed files. | 500 |
| LR_DEBUG | Print informational messages to the console. Allows you to see Livereload working. | true | | LR_DEBUG | Print informational messages to the console. Allows you to see Livereload working. | true |
| LR_HTTPS | Use HTTPS and WSS. In other words, use a certificate for SSL/TLS operation. | true | | LR_HTTPS | Use HTTPS and WSS. In other words, use a certificate for SSL/TLS operation. | true |
@@ -103,6 +103,8 @@ docker run -d --rm -v /var/www:/watch:ro -e LR_HTTPS=false -p 35729:35729 asifba
- `-p 35729:35729`: map on all interfaces port 35729 on the host --> port 35729 in container - `-p 35729:35729`: map on all interfaces port 35729 on the host --> port 35729 in container
- `listen`: start the Livereload server - `listen`: start the Livereload server
> Depending on your environment, you may *not* want to expose your Livereload server on all interfaces! You may want to map your port to something like `127.0.0.1:35729:35729` and then establishing an SSH-tunnel from your client. This is completely dependent on your environment and beyond the scope of this readme, sorry.
### Run in HTTPS mode with supplied certificate ### Run in HTTPS mode with supplied certificate
```bash ```bash
+3 -2
View File
@@ -23,7 +23,8 @@ EXPOSE 35729
RUN apk --update --no-cache add \ RUN apk --update --no-cache add \
tini \ tini \
tzdata \ tzdata \
openssl openssl \
&& apk --update --no-cache upgrade
# labels # labels
LABEL org.opencontainers.image.authors="Asif Bacchus <asif@asifbacchus.dev>" LABEL org.opencontainers.image.authors="Asif Bacchus <asif@asifbacchus.dev>"
@@ -40,7 +41,7 @@ ENV PATH=/home/node/.npm-global/bin:$PATH
ENV TZ="Etc/UTC" ENV TZ="Etc/UTC"
ENV LR_PORT=35729 ENV LR_PORT=35729
ENV LR_EXTS="html,xml,css,js,jsx,ts,tsx,php,py" ENV LR_EXTS="html,xml,css,js,jsx,ts,tsx,php,py"
ENV LR_EXCLUDE=".git/,.svn/,.vscode/,.idea/" ENV LR_EXCLUDE=".vscode/,.idea/,.tmp$,.swp$"
ENV LR_DELAY=500 ENV LR_DELAY=500
ENV LR_DEBUG=true ENV LR_DEBUG=true
ENV LR_HTTPS=true ENV LR_HTTPS=true
+11 -6
View File
@@ -1,6 +1,5 @@
// implement node-livereload over an HTTPS connection // implement node-livereload over an HTTP or HTTPS connection
// healthcheck function
function healthcheck() { function healthcheck() {
const express = require('express'); const express = require('express');
const http = require('http'); const http = require('http');
@@ -23,17 +22,23 @@ function healthcheck() {
hServer.listen(3000); hServer.listen(3000);
} }
// load livereload module // load modules
const livereload = require('livereload'); const livereload = require('livereload');
const fs = require('fs');
// process from environment variable as array and convert elements to RegEx objects
const extraExclusions = process.env.LR_EXCLUDE.split(",");
extraExclusions.forEach((exclusion, idx) => {
extraExclusions[idx] = new RegExp(exclusion);
});
// set createServer options // set createServer options
const fs = require('fs');
const options = { const options = {
port: process.env.LR_PORT, port: process.env.LR_PORT,
exts: process.env.LR_EXTS, exts: process.env.LR_EXTS,
exclusions: process.env.LR_EXCLUDE, exclusions: extraExclusions,
usePolling: true, usePolling: true,
delay: process.env.LR_DELAY, delay: process.env.LR_DELAY
}; };
// set debugging output as per LR_DEBUG // set debugging output as per LR_DEBUG