Skip to content

Commit a0629be

Browse files
committed
Add cache control
1 parent f276b5d commit a0629be

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const commandLineArgs = require('command-line-args');
22
const optionDefinitions = require('./options.js');
33
const getUsage = require('command-line-usage');
44
const express = require('express');
5+
const cacheControl = require('express-cache-controller');
56
const moment = require('moment');
67
const path = require('path');
78
const fs = require('fs');
@@ -72,6 +73,12 @@ function SaveGraph()
7273
}
7374
setInterval(SaveGraph, options.graphLogInterval);
7475

76+
// Setup cache
77+
app.use(cacheControl({
78+
public: true,
79+
maxAge: 60
80+
}));
81+
7582
//FORCE SSL
7683
app.use(function(req, res, next) {
7784
if (req.headers['x-forwarded-proto'] === 'http') {
@@ -92,6 +99,11 @@ app.get('/networkgraph', function(req, res) {
9299

93100
// Create payment invoice
94101
app.get('/getinvoice', function(req, res) {
102+
// Disable cache
103+
res.cacheControl = {
104+
noCache: true
105+
};
106+
95107
var value = parseInt(req.query.value);
96108

97109
if (!value || isNaN(value) || value < 1)
@@ -122,6 +134,11 @@ function isHexString(str)
122134

123135
// Reply with invoice status
124136
app.get('/invoicestatus', function(req, res) {
137+
// Disable cache
138+
res.cacheControl = {
139+
noCache: true
140+
};
141+
125142
var rhash = req.query.rhash;
126143

127144
if (!isHexString(rhash) || rhash.length != 64)

package-lock.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"command-line-args": "^5.0.1",
1313
"command-line-usage": "^4.1.0",
1414
"express": "^4.16.2",
15+
"express-cache-controller": "^1.1.0",
1516
"grpc": "^1.8.0",
1617
"moment": "^2.20.1"
1718
}

0 commit comments

Comments
 (0)