From 61da17940d24cfa899ff3086b5f53ffe9feb18ab Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 16 Jul 2025 18:53:38 +0100 Subject: [PATCH] Handle CORS preflight requests to the render export script --- cookbooks/tile/templates/default/export.erb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cookbooks/tile/templates/default/export.erb b/cookbooks/tile/templates/default/export.erb index eb35b1313..a0f8ff571 100644 --- a/cookbooks/tile/templates/default/export.erb +++ b/cookbooks/tile/templates/default/export.erb @@ -187,7 +187,13 @@ cputimes = [float(n) for n in open("/proc/stat").readline().rstrip().split()[1:- idletime = cputimes[3] / sum(cputimes) # Process the request -if not totp.verify(token, valid_window = 1): +if os.environ['REQUEST_METHOD'] == 'OPTIONS': + # Handle CORS preflight checks + print('Status: 204 No Content') + print('Access-Control-Allow-Origin: %s' % os.environ['HTTP_ORIGIN']) + print('Access-Control-Allow-Credentials: true') + print('') +elif not totp.verify(token, valid_window = 1): # Abort if the request didn't have a valid TOTP token output_error("Missing or invalid token") elif idletime < 0.2: -- 2.39.5