Skip to content

Commit fe3d585

Browse files
Use product version as etag to reload index.html
This is a temporary change where the eTag check is invokved from the boostrap.js .. but this logic should be on its own javascript file.
1 parent 9ea2a2c commit fe3d585

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

deps/rabbitmq_management/priv/www/index.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
<link href="css/main.css" rel="stylesheet" type="text/css"/>
2222
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon"/>
2323

24-
<script type="module">
25-
window.oauth = oauth_initialize_if_required()
26-
24+
<script type="module">
25+
window.oauth = oauth_initialize_if_required()
2726
</script>
2827

2928

deps/rabbitmq_management/priv/www/js/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,3 +1862,11 @@ function get_chart_range_type(arg) {
18621862
console.log('[WARNING]: range type not found for arg: ' + arg);
18631863
return 'basic';
18641864
}
1865+
1866+
function check_etag(etag) {
1867+
lastEtag = get_pref('etag')
1868+
if (!lastEtag || lastEtag != etag) {
1869+
store_pref('etag', etag)
1870+
location.reload()
1871+
}
1872+
}

deps/rabbitmq_management/src/rabbit_mgmt_oauth_bootstrap.erl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,21 @@ bootstrap_oauth(Req0, State) ->
1919
AuthSettings = rabbit_mgmt_wm_auth:authSettings(),
2020
Dependencies = oauth_dependencies(),
2121
JSContent = import_dependencies(Dependencies) ++
22+
check_etag() ++
2223
set_oauth_settings(AuthSettings) ++
2324
set_token_auth(AuthSettings, Req0) ++
2425
export_dependencies(Dependencies),
2526
{ok, cowboy_req:reply(200, #{<<"content-type">> => <<"text/javascript; charset=utf-8">>},
2627
JSContent, Req0), State}.
2728

29+
check_etag() ->
30+
ETag = case {rabbit:product_name(), rabbit:product_version()} of
31+
{undefined, _} -> rabbit:base_product_version();
32+
{_, undefined} -> rabbit:base_product_version();
33+
{_,_} -> rabbit:product_name() ++ " " ++ rabbit:product_version()
34+
end,
35+
["check_etag('" ++ ETag ++ "');"].
36+
2837
set_oauth_settings(AuthSettings) ->
2938
JsonAuthSettings = rabbit_json:encode(rabbit_mgmt_format:format_nulls(AuthSettings)),
3039
["set_oauth_settings(", JsonAuthSettings, ");"].

0 commit comments

Comments
 (0)