Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:9-alpine
FROM node:12-alpine

# Build-time
RUN set -ex \
Expand All @@ -13,8 +13,9 @@ RUN chown -R app /usr/charts-server
USER app

ENV ACCEPT_HIGHCHARTS_LICENSE YES
ENV HIGHCHARTS_VERSION latest
ENV HIGHCHARTS_USE_STYLED NO
ENV SERVER_CYCLE_MINUTES 720
ENV HIGHCHARTS_VERSION "6.2.0"
RUN npm install

USER root
Expand Down
20 changes: 19 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,26 @@ app.use(bodyParser.json({ limit: '50mb' }));

app.use('/charts', express.static('tmp/'));

var SERVER_CYCLE_MINUTES = parseInt(process.env['SERVER_CYCLE_MINUTES'], 10);

if (!SERVER_CYCLE_MINUTES || isNaN(SERVER_CYCLE_MINUTES)) {
console.error(`You must specify SERVER_CYCLE_MINUTES in the environment!`);
process.exit(1);
}

var UPTIME_CUT_OFF = SERVER_CYCLE_MINUTES * 60 * 1000;
var UPTIME_RANDOM_VARIATION_CAP = Math.floor(Math.random() * 10 * 60 * 1000); // 0-10 minutes grace

var serverStartTime = Date.now();

app.get('/health', function (req, res) {
res.send('OK');
var uptime = Date.now() - serverStartTime;
if (uptime < UPTIME_RANDOM_VARIATION_CAP + UPTIME_CUT_OFF) {
res.send('OK for ' + uptime + 'ms');
} else {
res.status(503);
res.send('Server has been up too long (' + uptime + 'ms)');
}
});

function enableRateLimiting(options) {
Expand Down