mirror of
https://github.com/bckelley/cgm-remote-monitor.git
synced 2026-08-24 03:14:12 -05:00
Merge pull request #4846 from GermanBluefox/patch-1
Allow start nightscout from other directories but cgm-remote-monitor
This commit is contained in:
@@ -18,12 +18,12 @@ function create (env, ctx) {
|
||||
if (!insecureUseHttp) {
|
||||
console.info('Redirecting http traffic to https because INSECURE_USE_HTTP=', insecureUseHttp);
|
||||
app.use((req, res, next) => {
|
||||
if (req.header('x-forwarded-proto') == 'https' || req.secure) {
|
||||
if (req.header('x-forwarded-proto') === 'https' || req.secure) {
|
||||
next();
|
||||
} else {
|
||||
res.redirect(307, `https://${req.header('host')}${req.url}`);
|
||||
}
|
||||
})
|
||||
});
|
||||
if (secureHstsHeader) { // Add HSTS (HTTP Strict Transport Security) header
|
||||
console.info('Enabled SECURE_HSTS_HEADER (HTTP Strict Transport Security)');
|
||||
const helmet = require('helmet');
|
||||
@@ -61,7 +61,7 @@ function create (env, ctx) {
|
||||
}));
|
||||
app.use(helmet.referrerPolicy({ policy: 'no-referrer' }));
|
||||
app.use(helmet.featurePolicy({ features: { payment: ["'none'"], } }));
|
||||
app.use(bodyParser.json({ type: ['json', 'application/csp-report'] }))
|
||||
app.use(bodyParser.json({ type: ['json', 'application/csp-report'] }));
|
||||
app.post('/report-violation', (req, res) => {
|
||||
if (req.body) {
|
||||
console.log('CSP Violation: ', req.body)
|
||||
@@ -84,7 +84,11 @@ function create (env, ctx) {
|
||||
|
||||
let cacheBuster = 'developmentMode';
|
||||
if (process.env.NODE_ENV !== 'development') {
|
||||
cacheBuster = fs.readFileSync(process.cwd() + '/tmp/cacheBusterToken').toString().trim();
|
||||
if (fs.existsSync(process.cwd() + '/tmp/cacheBusterToken')) {
|
||||
cacheBuster = fs.readFileSync(process.cwd() + '/tmp/cacheBusterToken').toString().trim();
|
||||
} else {
|
||||
cacheBuster = fs.readFileSync(__dirname + '/tmp/cacheBusterToken').toString().trim();
|
||||
}
|
||||
}
|
||||
app.locals.cachebuster = cacheBuster;
|
||||
|
||||
@@ -254,9 +258,16 @@ function create (env, ctx) {
|
||||
}
|
||||
|
||||
// Production bundling
|
||||
var tmpFiles = express.static('tmp', {
|
||||
maxAge: maxAge
|
||||
});
|
||||
var tmpFiles;
|
||||
if (fs.existsSync(process.cwd() + '/tmp/cacheBusterToken')) {
|
||||
tmpFiles = express.static('tmp', {
|
||||
maxAge: maxAge
|
||||
});
|
||||
} else {
|
||||
tmpFiles = express.static(__dirname + '/tmp', {
|
||||
maxAge: maxAge
|
||||
});
|
||||
}
|
||||
|
||||
// serve the static content
|
||||
app.use('/bundle', tmpFiles);
|
||||
|
||||
Reference in New Issue
Block a user