2021-07-22 16:43:17 -06:00
|
|
|
// implement node-livereload over an HTTPS connection
|
|
|
|
|
2021-07-24 03:01:01 -06:00
|
|
|
// healthcheck function
|
|
|
|
function healthcheck() {
|
|
|
|
const express = require('express');
|
|
|
|
const http = require('http');
|
|
|
|
|
|
|
|
const app = express();
|
|
|
|
const router = express.Router();
|
|
|
|
|
|
|
|
router.use((req, res, next) =>{
|
|
|
|
res.header('Access-Control-Allow-Methods', 'GET');
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
|
|
|
|
router.get('/health', (req, res) =>{
|
|
|
|
res.status(200).send('Ok');
|
|
|
|
});
|
|
|
|
|
|
|
|
app.use('/api/v1', router);
|
|
|
|
|
|
|
|
const hServer = http.createServer(app);
|
|
|
|
hServer.listen(3000);
|
|
|
|
}
|
|
|
|
|
2021-07-22 16:43:17 -06:00
|
|
|
// load livereload module
|
2021-07-24 03:01:01 -06:00
|
|
|
const livereload = require('livereload');
|
2021-07-22 16:43:17 -06:00
|
|
|
|
|
|
|
// set createServer options
|
|
|
|
const fs = require('fs');
|
|
|
|
const options = {
|
|
|
|
port: process.env.LR_PORT,
|
|
|
|
exts: process.env.LR_EXTS,
|
|
|
|
exclusions: process.env.LR_EXCLUDE,
|
|
|
|
usePolling: true,
|
2021-07-22 21:21:59 -06:00
|
|
|
delay: process.env.LR_DELAY,
|
2021-07-22 16:43:17 -06:00
|
|
|
};
|
|
|
|
|
2021-07-23 23:04:44 -06:00
|
|
|
// set debugging output as per LR_DEBUG
|
|
|
|
if (process.env.LR_DEBUG === "true") {
|
|
|
|
options.debug = true
|
2021-07-23 23:45:58 -06:00
|
|
|
console.log("[Debug output ENABLED]");
|
2021-07-23 23:04:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// set HTTPS as per LR_HTTPS
|
|
|
|
if (process.env.LR_HTTPS === "true") {
|
2021-07-23 13:31:01 -06:00
|
|
|
options.https = {
|
|
|
|
cert: fs.readFileSync('/certs/fullchain.pem'),
|
|
|
|
key: fs.readFileSync('/certs/privkey.pem')
|
|
|
|
};
|
2021-07-23 23:45:58 -06:00
|
|
|
console.log("[HTTPS mode]");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log("[HTTP mode]");
|
2021-07-23 13:31:01 -06:00
|
|
|
}
|
|
|
|
|
2021-07-22 16:43:17 -06:00
|
|
|
// start server
|
2021-07-24 03:01:01 -06:00
|
|
|
const lrServer = livereload.createServer(options, healthcheck);
|
|
|
|
lrServer.watch('/watch')
|
2021-07-22 16:43:17 -06:00
|
|
|
|
|
|
|
//#EOF
|