add cache control for index page (#150)

Co-authored-by: xssfox <xss@sprocketfox.io>
This commit is contained in:
Michaela Wheeler 2024-11-20 17:23:42 +11:00 committed by GitHub
parent ffd606d60c
commit b107f54d86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 64 additions and 0 deletions

58
cdn.tf
View File

@ -364,6 +364,52 @@ resource "aws_cloudfront_distribution" "sondehub" {
target_origin_id = "S3-${local.domain_name}"
viewer_protocol_policy = "redirect-to-https"
}
ordered_cache_behavior {
path_pattern = "index.html"
allowed_methods = ["GET", "HEAD", "OPTIONS"]
cached_methods = [
"HEAD",
"GET"
]
response_headers_policy_id = aws_cloudfront_response_headers_policy.no_cache.id
compress = true
forwarded_values {
cookies {
forward = "none"
}
query_string = false
}
max_ttl = 0
min_ttl = 0
default_ttl = 0
smooth_streaming = false
target_origin_id = "S3-${local.domain_name}"
viewer_protocol_policy = "redirect-to-https"
}
ordered_cache_behavior {
path_pattern = "/"
allowed_methods = ["GET", "HEAD", "OPTIONS"]
cached_methods = [
"HEAD",
"GET"
]
response_headers_policy_id = aws_cloudfront_response_headers_policy.no_cache.id
compress = true
forwarded_values {
cookies {
forward = "none"
}
query_string = false
}
max_ttl = 0
min_ttl = 0
default_ttl = 0
smooth_streaming = false
target_origin_id = "S3-${local.domain_name}"
viewer_protocol_policy = "redirect-to-https"
}
ordered_cache_behavior {
@ -599,6 +645,18 @@ resource "aws_cloudfront_distribution" "amateur" {
is_ipv6_enabled = true
}
resource "aws_cloudfront_response_headers_policy" "no_cache" {
name = "nocache"
custom_headers_config {
items {
header = "cache-control"
override = true
value = "no-cache"
}
}
}
resource "aws_cloudfront_distribution" "amateur_testing" {
aliases = [
"amateur-testing.sondehub.org"

View File

@ -34,4 +34,10 @@ def handler(event, context):
uri = re.sub(r"^\/","", uri)
sonde = re.sub(r'^(DFM|M10|M20|IMET|IMET54|MRZ|LMS6)-',"", uri)
return redirect('https://sondehub.org/?sondehub=1#!f=' + sonde + '&mz=9&qm=All&q=' + sonde)
request['headers']['cache-control'] = [
{
"key": "Cache-Control",
"value": "no-cache"
}
]
return request