Skip to content

Commit

Permalink
add cache control for index page (#150)
Browse files Browse the repository at this point in the history
Co-authored-by: xssfox <[email protected]>
  • Loading branch information
TheSkorm and xssfox authored Nov 20, 2024
1 parent ffd606d commit b107f54
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
58 changes: 58 additions & 0 deletions cdn.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions lambda/redirect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b107f54

Please sign in to comment.