diff --git a/cdn.tf b/cdn.tf index 2040c6e..4d22d3a 100644 --- a/cdn.tf +++ b/cdn.tf @@ -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" diff --git a/lambda/redirect/__init__.py b/lambda/redirect/__init__.py index 170e95c..ced3fff 100644 --- a/lambda/redirect/__init__.py +++ b/lambda/redirect/__init__.py @@ -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 \ No newline at end of file