Skip to content

Commit

Permalink
Merge pull request #122 from aroskanalen/feature/add-max-age-to-json-…
Browse files Browse the repository at this point in the history
…files

Added max-age and expires 1 hour to config.json and release.json
  • Loading branch information
tuj authored Apr 18, 2024
2 parents 530e777 + 21ce42d commit 3e25a74
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 49 deletions.
8 changes: 8 additions & 0 deletions .docker/vhost.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ server {
proxy_set_header Host $http_host;
proxy_pass http://node:3000;
}

location ~* ^/client/(config|release)\.json$ {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://node:3000;
add_header Cache-Control "public, max-age=3600";
expires 1h;
}
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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

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

Expand Down
6 changes: 6 additions & 0 deletions infrastructure/itkdev/etc/confd/templates/default.conf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ server {
return 200 "User-agent: *\nDisallow: /\n";
}

location ~* ^{{ getenv "APP_SCREEN_CLIENT_PATH" "" }}/(config|release)\.json$ {
add_header Cache-Control "public, max-age=3600";
expires 1h;
try_files $uri $uri/ =404;
}

error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ server {
return 200 "User-agent: *\nDisallow: /\n";
}

location ~* ^{{ getenv "APP_SCREEN_CLIENT_PATH" "" }}/(config|release)\.json$ {
add_header Cache-Control "public, max-age=3600";
expires 1h;
try_files $uri $uri/ =404;
}

error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
}
Expand Down
63 changes: 14 additions & 49 deletions src/app.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ describe('Client tests', () => {
fixture: 'awaiting-bind-key-response.json',
}).as('bindKey');

cy.intercept('GET', '**/config.json', {
statusCode: 200,
fixture: 'config.json',
}).as('config');

cy.visit('/');

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

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

cy.intercept('GET', '**/config.json', {
statusCode: 200,
fixture: 'config.json',
}).as('config');

cy.intercept('GET', '**/screens/01FYEDW1N133SG516JVJ3VG5FY', {
statusCode: 200,
fixture: 'screen-empty.json',
Expand All @@ -55,7 +57,6 @@ describe('Client tests', () => {

cy.wait([
'@bindKey',
'@config',
'@screen',
'@groups',
'@campaigns',
Expand All @@ -71,11 +72,6 @@ describe('Client tests', () => {
fixture: 'screen-response.json',
}).as('bindKey');

cy.intercept('GET', '**/config.json', {
statusCode: 200,
fixture: 'config.json',
}).as('config');

cy.intercept('GET', '**/screens/01FYEDW1N133SG516JVJ3VG5FY', {
statusCode: 200,
fixture: 'screen.json',
Expand Down Expand Up @@ -124,7 +120,7 @@ describe('Client tests', () => {

cy.wait([
'@bindKey',
'@config',
// '@config',
'@screen',
'@groups',
'@campaigns',
Expand All @@ -147,11 +143,6 @@ describe('Client tests', () => {
fixture: 'screen-response.json',
}).as('bindKey');

cy.intercept('GET', '**/config.json', {
statusCode: 200,
fixture: 'config.json',
}).as('config');

cy.intercept('GET', '**/screens/01FYEDW1N133SG516JVJ3VG5FY', {
statusCode: 200,
fixture: 'screen.json',
Expand Down Expand Up @@ -180,7 +171,6 @@ describe('Client tests', () => {
cy.visit('/');
cy.wait([
'@bindKey',
'@config',
'@screen',
'@groups',
'@campaigns',
Expand All @@ -200,11 +190,6 @@ describe('Client tests', () => {
fixture: 'screen-response.json',
}).as('bindKey');

cy.intercept('GET', '**/config.json', {
statusCode: 201,
fixture: 'config.json',
}).as('config');

cy.intercept('GET', '**/screens/01FYEDW1N133SG516JVJ3VG5FY', {
statusCode: 201,
fixture: 'screen.json',
Expand Down Expand Up @@ -247,7 +232,6 @@ describe('Client tests', () => {
cy.visit('/');
cy.wait([
'@bindKey',
'@config',
'@screen',
'@screen-groups',
'@screen-campaigns',
Expand All @@ -272,11 +256,6 @@ describe('Client tests', () => {
fixture: 'screen-response.json',
}).as('bindKey');

cy.intercept('GET', '**/config.json', {
statusCode: 201,
fixture: 'config.json',
}).as('config');

cy.intercept('GET', '**/screens/01FYEDW1N133SG516JVJ3VG5FY', {
statusCode: 201,
fixture: 'screen.json',
Expand Down Expand Up @@ -333,7 +312,6 @@ describe('Client tests', () => {
cy.visit('/');
cy.wait([
'@bindKey',
'@config',
'@screen',
'@groups',
'@campaigns',
Expand All @@ -356,11 +334,6 @@ describe('Client tests', () => {
fixture: 'screen-response.json',
}).as('bindKey');

cy.intercept('GET', '**/config.json', {
statusCode: 201,
fixture: 'config.json',
}).as('config');

cy.intercept('GET', '**/screens/01FYEDW1N133SG516JVJ3VG5FY', {
statusCode: 201,
fixture: 'screen.json',
Expand Down Expand Up @@ -417,7 +390,6 @@ describe('Client tests', () => {
cy.visit('/');
cy.wait([
'@bindKey',
'@config',
'@screen',
'@groups',
'@campaigns',
Expand All @@ -440,11 +412,6 @@ describe('Client tests', () => {
fixture: 'screen-response.json',
}).as('bindKey');

cy.intercept('GET', '**/config.json', {
statusCode: 201,
fixture: 'config.json',
}).as('config');

cy.intercept('GET', '**/screens/01FYEDW1N133SG516JVJ3VG5FY', {
statusCode: 201,
fixture: 'screen-diff-layout.json',
Expand Down Expand Up @@ -493,7 +460,11 @@ describe('Client tests', () => {
}).as('layout');

cy.visit('/');
cy.wait(['@bindKey', '@config', '@screen', '@layout']);
cy.wait([
'@bindKey',
'@screen',
'@layout',
]);

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

cy.intercept('GET', '**/config.json', {
statusCode: 201,
fixture: 'config.json',
}).as('config');

cy.intercept('GET', '**/screens/01FYEDW1N133SG516JVJ3VG5FY', {
statusCode: 201,
fixture: 'screen.json',
Expand Down Expand Up @@ -577,7 +543,6 @@ describe('Client tests', () => {
cy.visit('/');
cy.wait([
'@bindKey',
'@config',
'@screen',
'@groups',
'@campaigns',
Expand Down

0 comments on commit 3e25a74

Please sign in to comment.