Skip to content

Commit 3e25a74

Browse files
authored
Merge pull request #122 from aroskanalen/feature/add-max-age-to-json-files
Added max-age and expires 1 hour to config.json and release.json
2 parents 530e777 + 21ce42d commit 3e25a74

File tree

5 files changed

+36
-49
lines changed

5 files changed

+36
-49
lines changed

.docker/vhost.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,12 @@ server {
88
proxy_set_header Host $http_host;
99
proxy_pass http://node:3000;
1010
}
11+
12+
location ~* ^/client/(config|release)\.json$ {
13+
proxy_set_header X-Forwarded-For $remote_addr;
14+
proxy_set_header Host $http_host;
15+
proxy_pass http://node:3000;
16+
add_header Cache-Control "public, max-age=3600";
17+
expires 1h;
18+
}
1119
}

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
- [#122](https://github.com/os2display/display-client/pull/122)
6+
- Added max-age and expires 1 hour to config.json and release.json.
57
- [#121](https://github.com/os2display/display-client/pull/120)
68
- Add releaseVersion, releaseTimestamp and screenId searchParams when starting app.
79

infrastructure/itkdev/etc/confd/templates/default.conf.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ server {
1616
return 200 "User-agent: *\nDisallow: /\n";
1717
}
1818

19+
location ~* ^{{ getenv "APP_SCREEN_CLIENT_PATH" "" }}/(config|release)\.json$ {
20+
add_header Cache-Control "public, max-age=3600";
21+
expires 1h;
22+
try_files $uri $uri/ =404;
23+
}
24+
1925
error_log /var/log/nginx/error.log;
2026
access_log /var/log/nginx/access.log;
2127
}

infrastructure/os2display/etc/confd/templates/default.conf.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ server {
1616
return 200 "User-agent: *\nDisallow: /\n";
1717
}
1818

19+
location ~* ^{{ getenv "APP_SCREEN_CLIENT_PATH" "" }}/(config|release)\.json$ {
20+
add_header Cache-Control "public, max-age=3600";
21+
expires 1h;
22+
try_files $uri $uri/ =404;
23+
}
24+
1925
error_log /var/log/nginx/error.log;
2026
access_log /var/log/nginx/access.log;
2127
}

src/app.spec.js

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ describe('Client tests', () => {
1010
fixture: 'awaiting-bind-key-response.json',
1111
}).as('bindKey');
1212

13+
cy.intercept('GET', '**/config.json', {
14+
statusCode: 200,
15+
fixture: 'config.json',
16+
}).as('config');
17+
1318
cy.visit('/');
1419

15-
cy.wait('@bindKey');
20+
// After this point we assume the config file is served from the browser
21+
// cache, since it the nginx setup has a 1h caching set for config.json.
22+
cy.wait(['@bindKey', '@config']);
1623

1724
cy.get('.bind-key').should('exist');
1825
cy.get('.bind-key')
@@ -26,11 +33,6 @@ describe('Client tests', () => {
2633
fixture: 'screen-response.json',
2734
}).as('bindKey');
2835

29-
cy.intercept('GET', '**/config.json', {
30-
statusCode: 200,
31-
fixture: 'config.json',
32-
}).as('config');
33-
3436
cy.intercept('GET', '**/screens/01FYEDW1N133SG516JVJ3VG5FY', {
3537
statusCode: 200,
3638
fixture: 'screen-empty.json',
@@ -55,7 +57,6 @@ describe('Client tests', () => {
5557

5658
cy.wait([
5759
'@bindKey',
58-
'@config',
5960
'@screen',
6061
'@groups',
6162
'@campaigns',
@@ -71,11 +72,6 @@ describe('Client tests', () => {
7172
fixture: 'screen-response.json',
7273
}).as('bindKey');
7374

74-
cy.intercept('GET', '**/config.json', {
75-
statusCode: 200,
76-
fixture: 'config.json',
77-
}).as('config');
78-
7975
cy.intercept('GET', '**/screens/01FYEDW1N133SG516JVJ3VG5FY', {
8076
statusCode: 200,
8177
fixture: 'screen.json',
@@ -124,7 +120,7 @@ describe('Client tests', () => {
124120

125121
cy.wait([
126122
'@bindKey',
127-
'@config',
123+
// '@config',
128124
'@screen',
129125
'@groups',
130126
'@campaigns',
@@ -147,11 +143,6 @@ describe('Client tests', () => {
147143
fixture: 'screen-response.json',
148144
}).as('bindKey');
149145

150-
cy.intercept('GET', '**/config.json', {
151-
statusCode: 200,
152-
fixture: 'config.json',
153-
}).as('config');
154-
155146
cy.intercept('GET', '**/screens/01FYEDW1N133SG516JVJ3VG5FY', {
156147
statusCode: 200,
157148
fixture: 'screen.json',
@@ -180,7 +171,6 @@ describe('Client tests', () => {
180171
cy.visit('/');
181172
cy.wait([
182173
'@bindKey',
183-
'@config',
184174
'@screen',
185175
'@groups',
186176
'@campaigns',
@@ -200,11 +190,6 @@ describe('Client tests', () => {
200190
fixture: 'screen-response.json',
201191
}).as('bindKey');
202192

203-
cy.intercept('GET', '**/config.json', {
204-
statusCode: 201,
205-
fixture: 'config.json',
206-
}).as('config');
207-
208193
cy.intercept('GET', '**/screens/01FYEDW1N133SG516JVJ3VG5FY', {
209194
statusCode: 201,
210195
fixture: 'screen.json',
@@ -247,7 +232,6 @@ describe('Client tests', () => {
247232
cy.visit('/');
248233
cy.wait([
249234
'@bindKey',
250-
'@config',
251235
'@screen',
252236
'@screen-groups',
253237
'@screen-campaigns',
@@ -272,11 +256,6 @@ describe('Client tests', () => {
272256
fixture: 'screen-response.json',
273257
}).as('bindKey');
274258

275-
cy.intercept('GET', '**/config.json', {
276-
statusCode: 201,
277-
fixture: 'config.json',
278-
}).as('config');
279-
280259
cy.intercept('GET', '**/screens/01FYEDW1N133SG516JVJ3VG5FY', {
281260
statusCode: 201,
282261
fixture: 'screen.json',
@@ -333,7 +312,6 @@ describe('Client tests', () => {
333312
cy.visit('/');
334313
cy.wait([
335314
'@bindKey',
336-
'@config',
337315
'@screen',
338316
'@groups',
339317
'@campaigns',
@@ -356,11 +334,6 @@ describe('Client tests', () => {
356334
fixture: 'screen-response.json',
357335
}).as('bindKey');
358336

359-
cy.intercept('GET', '**/config.json', {
360-
statusCode: 201,
361-
fixture: 'config.json',
362-
}).as('config');
363-
364337
cy.intercept('GET', '**/screens/01FYEDW1N133SG516JVJ3VG5FY', {
365338
statusCode: 201,
366339
fixture: 'screen.json',
@@ -417,7 +390,6 @@ describe('Client tests', () => {
417390
cy.visit('/');
418391
cy.wait([
419392
'@bindKey',
420-
'@config',
421393
'@screen',
422394
'@groups',
423395
'@campaigns',
@@ -440,11 +412,6 @@ describe('Client tests', () => {
440412
fixture: 'screen-response.json',
441413
}).as('bindKey');
442414

443-
cy.intercept('GET', '**/config.json', {
444-
statusCode: 201,
445-
fixture: 'config.json',
446-
}).as('config');
447-
448415
cy.intercept('GET', '**/screens/01FYEDW1N133SG516JVJ3VG5FY', {
449416
statusCode: 201,
450417
fixture: 'screen-diff-layout.json',
@@ -493,7 +460,11 @@ describe('Client tests', () => {
493460
}).as('layout');
494461

495462
cy.visit('/');
496-
cy.wait(['@bindKey', '@config', '@screen', '@layout']);
463+
cy.wait([
464+
'@bindKey',
465+
'@screen',
466+
'@layout',
467+
]);
497468

498469
cy.get('.region')
499470
.eq(0)
@@ -511,11 +482,6 @@ describe('Client tests', () => {
511482
fixture: 'screen-response.json',
512483
}).as('bindKey');
513484

514-
cy.intercept('GET', '**/config.json', {
515-
statusCode: 201,
516-
fixture: 'config.json',
517-
}).as('config');
518-
519485
cy.intercept('GET', '**/screens/01FYEDW1N133SG516JVJ3VG5FY', {
520486
statusCode: 201,
521487
fixture: 'screen.json',
@@ -577,7 +543,6 @@ describe('Client tests', () => {
577543
cy.visit('/');
578544
cy.wait([
579545
'@bindKey',
580-
'@config',
581546
'@screen',
582547
'@groups',
583548
'@campaigns',

0 commit comments

Comments
 (0)