diff --git a/index.js b/index.js index cf16409..da587dd 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ const commandLineArgs = require('command-line-args'); const optionDefinitions = require('./options.js'); const getUsage = require('command-line-usage'); const express = require('express'); +const cacheControl = require('express-cache-controller'); const moment = require('moment'); const path = require('path'); const fs = require('fs'); @@ -72,6 +73,12 @@ function SaveGraph() } setInterval(SaveGraph, options.graphLogInterval); +// Setup cache +app.use(cacheControl({ + public: true, + maxAge: 60 +})); + //FORCE SSL app.use(function(req, res, next) { if (req.headers['x-forwarded-proto'] === 'http') { @@ -92,6 +99,11 @@ app.get('/networkgraph', function(req, res) { // Create payment invoice app.get('/getinvoice', function(req, res) { + // Disable cache + res.cacheControl = { + noCache: true + }; + var value = parseInt(req.query.value); if (!value || isNaN(value) || value < 1) @@ -122,6 +134,11 @@ function isHexString(str) // Reply with invoice status app.get('/invoicestatus', function(req, res) { + // Disable cache + res.cacheControl = { + noCache: true + }; + var rhash = req.query.rhash; if (!isHexString(rhash) || rhash.length != 64) diff --git a/package-lock.json b/package-lock.json index 2bd25ce..9336fa9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -264,6 +264,15 @@ "vary": "1.1.2" } }, + "express-cache-controller": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/express-cache-controller/-/express-cache-controller-1.1.0.tgz", + "integrity": "sha512-aRGah9AdVUqyChcFjbL03SVW0c6siE871wzMRuXxCONzYiBDmUtGFEnzZP1ABM6nCo3ovnKPntFRFzAxGqmWtw==", + "requires": { + "lodash.isnumber": "3.0.3", + "on-headers": "1.0.1" + } + }, "finalhandler": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.0.tgz", @@ -1113,6 +1122,11 @@ "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", "integrity": "sha1-soqmKIorn8ZRA1x3EfZathkDMaY=" }, + "lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w=" + }, "lodash.padend": { "version": "4.6.1", "resolved": "https://registry.npmjs.org/lodash.padend/-/lodash.padend-4.6.1.tgz", @@ -1197,6 +1211,11 @@ "ee-first": "1.1.1" } }, + "on-headers": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.1.tgz", + "integrity": "sha1-ko9dD0cNSTQmUepnlLCFfBAGk/c=" + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", diff --git a/package.json b/package.json index 9ac228c..917f50d 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "command-line-args": "^5.0.1", "command-line-usage": "^4.1.0", "express": "^4.16.2", + "express-cache-controller": "^1.1.0", "grpc": "^1.8.0", "moment": "^2.20.1" }