Skip to content

Commit cf31fe7

Browse files
authored
Merge pull request #124 from aroskanalen/feature/max-age
1186: Changed to apply max-age 7d to all files and added cache busting
2 parents 3e25a74 + 47aedaa commit cf31fe7

File tree

16 files changed

+170
-90
lines changed

16 files changed

+170
-90
lines changed

.docker/vhost.conf

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ server {
77
proxy_set_header X-Forwarded-For $remote_addr;
88
proxy_set_header Host $http_host;
99
proxy_pass http://node:3000;
10-
}
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;
10+
add_header Cache-Control "public, max-age=604800";
11+
expires 7d;
1812
}
1913
}

CHANGELOG.md

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

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

5+
- [#123](https://github.com/os2display/display-client/pull/123)
6+
- Changed to apply max-age 7d to all files and added cache busting to config.json and release.json.
7+
- Added "loginCheckTimeout", "configFetchInterval", "refreshTokenTimeout", "releaseTimestampIntervalTimeout" to config.json.
8+
- Simplified config.json.
59
- [#122](https://github.com/os2display/display-client/pull/122)
610
- Added max-age and expires 1 hour to config.json and release.json.
711
- [#121](https://github.com/os2display/display-client/pull/120)

README.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,30 @@ See [https://github.com/os2display/display-docs/blob/main/client.md](https://git
55

66
## Config
77
The client can be configured by creating `public/config.json` with relevant values.
8-
See `public/example_config.json` for values.
9-
10-
```json
11-
{
12-
"apiEndpoint": "",
13-
"authenticationEndpoint": "/v2/authentication/screen",
14-
"authenticationRefreshTokenEndpoint": "/v2/authentication/token/refresh",
15-
"dataStrategy": {
16-
"type": "pull",
17-
"config": {
18-
"interval": 30000,
19-
"endpoint": ""
20-
}
21-
},
22-
"colorScheme": {
23-
"type": "library",
24-
"lat": 56.0,
25-
"lng": 10.0
26-
},
27-
"schedulingInterval": 60000,
28-
"debug": false
29-
}
30-
```
31-
All endpoint should be configured with out a trailing slash. The endpoints `apiEndpoint` and `dataStrategy.config.endpoint` can be
8+
See `public/example_config.json` for example values.
9+
10+
Values explained:
11+
12+
* apiEndpoint - The endpoint where the API is located.
13+
* loginCheckTimeout - How often (milliseconds) should the screen check for
14+
status when it is not logged in, and waiting for being activated in the
15+
administration.
16+
* configFetchInterval - How often (milliseconds) should a fresh
17+
config.json be fetched.
18+
* refreshTokenTimeout - How often (milliseconds) should it be checked
19+
whether the token needs to be refreshed?
20+
* releaseTimestampIntervalTimeout - How often (milliseconds) should the
21+
code check if a new release has been deployed, and reload if true?
22+
* dataStrategy.config.interval - How often (milliseconds) should data be fetched
23+
for the logged in screen?
24+
* colorScheme.lat - Where is the screen located? Used for darkmode.
25+
* colorScheme.lng - Where is the screen located? Used for darkmode.
26+
* schedulingInterval - How often (milliseconds) should scheduling for the
27+
screen be checked.
28+
* debug - Should the screen be in debug mode? If true, the cursor will be
29+
invisible.
30+
31+
All endpoint should be configured without a trailing slash. The endpoints `apiEndpoint` can be
3232
left empty if the api is hosted from the root of the same domain as the client. E.g. if the api is at https://example.org and the client is at
3333
https://example.org/client
3434

infrastructure/itkdev/etc/confd/templates/config.tmpl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"apiEndpoint": "{{ getenv "APP_API_ENDPOINT" "" }}",
3-
"authenticationEndpoint": "{{ getenv "APP_API_AUTHENTICATION_ENDPOINT" "/v2/authentication/token" }}",
4-
"authenticationRefreshTokenEndpoint": "{{ getenv "APP_API_AUTHENTICATION_REFRESH_ENDPOINT" "/v2/authentication/token/refresh" }}",
3+
"loginCheckTimeout": {{ getenv "APP_LOGIN_CHECK_TIMEOUT" "20000" }},
4+
"configFetchInterval": {{ getenv "APP_CONFIG_FETCH_INTERVAL" "600000" }},
5+
"refreshTokenTimeout": {{ getenv "APP_REFRESH_TOKEN_TIMEOUT" "60000" }},
6+
"releaseTimestampIntervalTimeout": {{ getenv "APP_RELEASE_TIMESTAMP_INTERVAL_TIMEOUT" "600000" }},
57
"dataStrategy": {
68
"type": "pull",
79
"config": {
8-
"interval": {{ getenv "APP_DATA_PULL_INTERVAL" "30000" }},
9-
"endpoint": "{{ getenv "APP_API_PATH" "" }}"
10+
"interval": {{ getenv "APP_DATA_PULL_INTERVAL" "30000" }}
1011
}
1112
},
1213
"colorScheme": {

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ server {
77
rewrite ^{{ getenv "APP_SCREEN_CLIENT_PATH" "/" }}(.*) /$1 break;
88
index index.html;
99
autoindex off;
10+
add_header Cache-Control "public, max-age=604800";
11+
expires 7d;
1012
try_files $uri $uri/ =404;
1113
}
1214

@@ -16,12 +18,6 @@ server {
1618
return 200 "User-agent: *\nDisallow: /\n";
1719
}
1820

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-
2521
error_log /var/log/nginx/error.log;
2622
access_log /var/log/nginx/access.log;
2723
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
11
# OS2display image build
22

33
This folder contains the infrastructure files for building the `os2display/display-client` image.
4+
5+
## Environment variables that can be set
6+
7+
### config.json
8+
9+
* APP_API_ENDPOINT - The endpoint where the API can be called.
10+
* APP_LOGIN_CHECK_TIMEOUT - How often (milliseconds) should the screen check for
11+
status when it is not logged in, and waiting for being activated in the
12+
administration.
13+
* APP_CONFIG_FETCH_INTERVAL - How often (milliseconds) should a fresh
14+
config.json be fetched.
15+
* APP_REFRESH_TOKEN_TIMEOUT - How often (milliseconds) should it be checked
16+
whether the token needs to be refreshed?
17+
* APP_RELEASE_TIMESTAMP_INTERVAL_TIMEOUT - How often (milliseconds) should the
18+
code check if a new release has been deployed, and reload if true?
19+
* APP_DATA_PULL_INTERVAL - How often (milliseconds) should data be fetched for
20+
the logged in screen?
21+
* APP_CLIENT_LATITUDE - Where is the screen located? Used for darkmode.
22+
* APP_CLIENT_LONGITUDE - Where is the screen located? Used for darkmode.
23+
* APP_SCHEDULING_INTERVAL - How often (milliseconds) should scheduling for the
24+
screen be checked.
25+
* APP_DEBUG - Should the screen be in debug mode? If true, the cursor will be
26+
invisible.

infrastructure/os2display/etc/confd/templates/config.tmpl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"apiEndpoint": "{{ getenv "APP_API_ENDPOINT" "/" }}",
3-
"authenticationEndpoint": "{{ getenv "APP_API_AUTHENTICATION_ENDPOINT" "/v2/authentication/token" }}",
4-
"authenticationRefreshTokenEndpoint": "{{ getenv "APP_API_AUTHENTICATION_REFRESH_ENDPOINT" "/v2/authentication/token/refresh" }}",
3+
"loginCheckTimeout": {{ getenv "APP_LOGIN_CHECK_TIMEOUT" "20000" }},
4+
"configFetchInterval": {{ getenv "APP_CONFIG_FETCH_INTERVAL" "600000" }},
5+
"refreshTokenTimeout": {{ getenv "APP_REFRESH_TOKEN_TIMEOUT" "60000" }},
6+
"releaseTimestampIntervalTimeout": {{ getenv "APP_RELEASE_TIMESTAMP_INTERVAL_TIMEOUT" "600000" }},
57
"dataStrategy": {
68
"type": "pull",
79
"config": {
8-
"interval": {{ getenv "APP_DATA_PULL_INTERVAL" "30000" }},
9-
"endpoint": "{{ getenv "APP_API_PATH" "/" }}"
10+
"interval": {{ getenv "APP_DATA_PULL_INTERVAL" "30000" }}
1011
}
1112
},
1213
"colorScheme": {

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ server {
77
rewrite ^{{ getenv "APP_SCREEN_CLIENT_PATH" "/" }}(.*) /$1 break;
88
index index.html;
99
autoindex off;
10+
add_header Cache-Control "public, max-age=604800";
11+
expires 7d;
1012
try_files $uri $uri/ =404;
1113
}
1214

@@ -16,12 +18,6 @@ server {
1618
return 200 "User-agent: *\nDisallow: /\n";
1719
}
1820

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-
2521
error_log /var/log/nginx/error.log;
2622
access_log /var/log/nginx/access.log;
2723
}

public/example_config.json

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
2-
"apiEndpoint": "",
3-
"authenticationEndpoint": "/v2/authentication/screen",
4-
"authenticationRefreshTokenEndpoint": "/v2/authentication/token/refresh",
2+
"apiEndpoint": "https://os2display.example.org",
3+
"loginCheckTimeout": 20000,
4+
"configFetchInterval": 90000,
5+
"refreshTokenTimeout": 900000,
6+
"releaseTimestampIntervalTimeout": 600000,
57
"dataStrategy": {
68
"type": "pull",
79
"config": {
8-
"interval": 30000,
9-
"endpoint": ""
10+
"interval": 30000
1011
}
1112
},
1213
"colorScheme": {
@@ -15,5 +16,11 @@
1516
"lng": 10.0
1617
},
1718
"schedulingInterval": 60000,
18-
"debug": false
19+
"debug": false,
20+
"logging": [
21+
{
22+
"transport": "console",
23+
"level": "info"
24+
}
25+
]
1926
}

src/app.js

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ function App() {
2121
localStorageKeys.FALLBACK_IMAGE
2222
);
2323

24-
const loginCheckTimeout = 15 * 1000;
25-
const refreshTimeout = 60 * 1000;
26-
const releaseTimestampIntervalTimeout = 1000 * 60 * 5;
24+
const loginCheckTimeoutDefault = 20 * 1000;
25+
const refreshTokenTimeoutDefault = 60 * 1000 * 15;
26+
const releaseTimestampIntervalTimeoutDefault = 1000 * 60 * 10;
2727

2828
const [running, setRunning] = useState(false);
2929
const [screen, setScreen] = useState('');
@@ -97,7 +97,7 @@ function App() {
9797
Logger.log('info', 'Refreshing token.');
9898

9999
ConfigLoader.loadConfig().then((config) => {
100-
fetch(config.authenticationRefreshTokenEndpoint, {
100+
fetch(`${config.apiEndpoint}/v2/authentication/token/refresh`, {
101101
method: 'POST',
102102
headers: {
103103
'Content-Type': 'application/json',
@@ -168,8 +168,13 @@ function App() {
168168
})
169169
);
170170

171-
// Start refresh token interval.
172-
refreshTokenIntervalRef.current = setInterval(checkToken, refreshTimeout);
171+
ConfigLoader.loadConfig().then((config) => {
172+
// Start refresh token interval.
173+
refreshTokenIntervalRef.current = setInterval(
174+
checkToken,
175+
config.refreshTokenTimeout ?? refreshTokenTimeoutDefault
176+
);
177+
});
173178
};
174179

175180
const checkLogin = () => {
@@ -182,7 +187,7 @@ function App() {
182187
startContent(localScreenId);
183188
} else {
184189
ConfigLoader.loadConfig().then((config) => {
185-
fetch(config.authenticationEndpoint, {
190+
fetch(`${config.apiEndpoint}/v2/authentication/screen`, {
186191
method: 'POST',
187192
mode: 'cors',
188193
credentials: 'include',
@@ -225,15 +230,21 @@ function App() {
225230
clearTimeout(timeoutRef.current);
226231
}
227232

228-
timeoutRef.current = setTimeout(checkLogin, loginCheckTimeout);
233+
timeoutRef.current = setTimeout(
234+
checkLogin,
235+
config.loginCheckTimeout ?? loginCheckTimeoutDefault
236+
);
229237
}
230238
})
231239
.catch(() => {
232240
if (timeoutRef.current !== null) {
233241
clearTimeout(timeoutRef.current);
234242
}
235243

236-
timeoutRef.current = setTimeout(checkLogin, loginCheckTimeout);
244+
timeoutRef.current = setTimeout(
245+
checkLogin,
246+
config.loginCheckTimeout ?? loginCheckTimeoutDefault
247+
);
237248
});
238249
});
239250
}
@@ -331,10 +342,13 @@ function App() {
331342

332343
checkForUpdates();
333344

334-
releaseTimestampIntervalRef.current = setInterval(
335-
checkForUpdates,
336-
releaseTimestampIntervalTimeout
337-
);
345+
ConfigLoader.loadConfig().then((config) => {
346+
releaseTimestampIntervalRef.current = setInterval(
347+
checkForUpdates,
348+
config.releaseTimestampIntervalTimeout ??
349+
releaseTimestampIntervalTimeoutDefault
350+
);
351+
});
338352

339353
return function cleanup() {
340354
Logger.log('info', 'Unmounting App.');
@@ -361,7 +375,7 @@ function App() {
361375

362376
useEffect(() => {
363377
// Append screenId to current url for easier debugging. If errors are logged in the API's standard http log this
364-
// makes it easy to see what screen client has made the http call by putting the screen id in the referer http
378+
// makes it easy to see what screen client has made the http call by putting the screen id in the referer http
365379
// header.
366380
if (screen && screen['@id']) {
367381
const url = new URL(window.location.href);

0 commit comments

Comments
 (0)