From c2cc1189e046064daf0151df358a10a687f5e2da Mon Sep 17 00:00:00 2001 From: thevickypedia Date: Wed, 6 Dec 2023 22:55:02 -0600 Subject: [PATCH] Simplify CORS and enhance video box for mobile devices --- pystream/main.py | 14 +++++--------- pystream/templates/index.html | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/pystream/main.py b/pystream/main.py index 4825eca..194513b 100644 --- a/pystream/main.py +++ b/pystream/main.py @@ -21,23 +21,19 @@ def task() -> None: def startup_tasks() -> None: """Tasks that need to run during the API startup.""" - logger.info('Setting CORS policy.') origins = ["http://localhost.com", "https://localhost.com"] if config.env.website: + logger.info('Setting CORS policy.') origins.extend([ f"http://{config.env.website.host}", f"https://{config.env.website.host}", f"http://{config.env.website.host}/*", f"https://{config.env.website.host}/*" ]) - app.add_middleware( - CORSMiddleware, - allow_origins=origins, - allow_origin_regex='https://.*\.ngrok\.io/*', # noqa: W605 - allow_credentials=True, - allow_methods=["*"], - allow_headers=["*"], - ) + kwargs = dict(allow_origins=origins) + if config.env.ngrok_token: + kwargs['allow_origin_regex'] = 'https://.*\.ngrok\.io/*' # noqa: W605 + app.add_middleware(CORSMiddleware, **kwargs) task() diff --git a/pystream/templates/index.html b/pystream/templates/index.html index dc1ae15..4b39249 100644 --- a/pystream/templates/index.html +++ b/pystream/templates/index.html @@ -74,6 +74,25 @@ text-align: center; } + + @@ -81,8 +100,8 @@

{{title}}

+
+