Skip to content

Commit

Permalink
Avoid caching the root HTML pages
Browse files Browse the repository at this point in the history
Avoid caching the / (index.html) and 50x.html pages
  • Loading branch information
mz2 authored Aug 14, 2023
1 parent 6b7c71a commit 0761831
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion frontend/charm/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _on_rest_api_relation_update(self, event):
def _on_rest_api_relation_broken(self, event):
logger.debug("REST API relation broken")
self._update_layer_and_restart(event)

def nginx_config(self, base_uri: str) -> str:
"""Return a config where the backend port `base_uri` is adjusted."""
return f"""
Expand All @@ -109,6 +109,10 @@ def nginx_config(self, base_uri: str) -> str:
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
# Ensure no caching
expires -1;
add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
sub_filter 'http://api-placeholder:30000/' '{base_uri}';
sub_filter_once on;
}}
Expand All @@ -132,6 +136,10 @@ def nginx_503_config(self) -> str:
location @maintenance {
rewrite ^(.*)$ /503.html break;
root /usr/share/nginx/html;
# Ensure no caching
expires -1;
add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
}
}
"""
Expand Down

0 comments on commit 0761831

Please sign in to comment.