From 90286323b65e6820129584852a65808911c5bbc7 Mon Sep 17 00:00:00 2001 From: Oscar Vestlie Date: Thu, 11 Jan 2024 19:42:30 -0800 Subject: [PATCH] Fix redirect location to handle / (#2204) b/236404667 --- cobalt/site/deploy/main.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cobalt/site/deploy/main.py b/cobalt/site/deploy/main.py index eb4d4519fd6f..7619587a3e4a 100644 --- a/cobalt/site/deploy/main.py +++ b/cobalt/site/deploy/main.py @@ -25,11 +25,14 @@ def app(environ, start_response): Changing the file or function name requires configuring a matching entrypoint. """ - base_url = 'https://developers.google.com' - path_prefix = '/youtube/cobalt/docs' + base_url = 'https://developers.google.com/youtube/cobalt' + doc_prefix = '/docs' # Remove extension from filename if present. doc_path = os.path.splitext(environ['RAW_URI'])[0] + if not doc_path or doc_path == '/': + location = base_url + else: + location = f'{base_url}{doc_prefix}{doc_path}' - start_response('301 Moved Permanently', - [('Location', f'{base_url}{path_prefix}{doc_path}')]) + start_response('301 Moved Permanently', [('Location', location)]) return []