Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HOFF-999 setting nginx rate limiter - ARE as a test #153

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
A calculator to determine Appeal Rights Exhausted

# Setup
# Comment to trigger a build to test nginx ratew limiter on the nginx deployment

## Install prerequisites

Expand Down
74 changes: 9 additions & 65 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,11 @@
/* eslint-disable no-undef */
const express = require('express')
const app = express()
const port = 8080

'use strict';
app.get('/', (req, res) => {
res.send('Hello World!')
})

const hof = require('hof');
let settings = require('./hof.settings');
const ExclusionDates = require('./apps/are_form/models/exclusion_dates');
const config = require('./config.js');

settings = Object.assign({}, settings, {
behaviours: settings.behaviours.map(require),
routes: settings.routes.map(require),
getCookies: false,
getTerms: false,
getAccessibility: false,
csp: {
imgSrc: [
'www.google-analytics.com',
'ssl.gstatic.com',
'www.google.co.uk/ads/ga-audiences'
],
connectSrc: [
'https://www.google-analytics.com',
'https://region1.google-analytics.com',
'https://region1.analytics.google.com'
]
}
});

// overwrite exclusion_days.json once a day
setInterval(() => {
const exclusionDates = new ExclusionDates();
exclusionDates.saveExclusionDays();
}, 1000 * 60 * 60 * 24);

// overwrite exclusion_days.json with latest API data and start the application
const exclusionDates = new ExclusionDates();

exclusionDates.saveExclusionDays()
.then(() => {
const app = hof(settings);

app.use((req, res, next) => {
res.locals.htmlLang = 'en';
// Set feedback link and phase banner
res.locals.feedbackUrl = config.survey.urls.root;
next();
});

// Set feedback and phase banner on cookies, accessibility and terms pages
// along with the getTerms: false, getCookies: false, getAccessibility: false config
app.use('/terms-and-conditions', (req, res, next) => {
res.locals = Object.assign({}, res.locals, req.translate('terms'));
next();
});

app.use('/cookies', (req, res, next) => {
res.locals = Object.assign({}, res.locals, req.translate('cookies'));
next();
});

app.use('/accessibility', (req, res, next) => {
res.locals = Object.assign({}, res.locals, req.translate('accessibility'));
next();
});
module.exports = app;
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})