From e4ca27a84dbc50c34616d178caea589763a1ffb2 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Tue, 29 Nov 2022 15:12:04 -0500 Subject: [PATCH] Improved CORS!!!! --- app/config.py.default | 22 ++++++++++++++ app/main.py | 67 ++++--------------------------------------- 2 files changed, 27 insertions(+), 62 deletions(-) diff --git a/app/config.py.default b/app/config.py.default index 9eee58c..a56659a 100644 --- a/app/config.py.default +++ b/app/config.py.default @@ -30,6 +30,28 @@ class Settings(BaseSettings): FILES_PATH = {} + # CORS Origins + ORIGINS_REGEX = '(https://.*\.oneskyit\.com)|(http://.*\.oneskyit\.local)|(http://.*\.oneskyit\.local:5000)|(http://.*.localhost)|(http://.*.localhost:5000)' + + ORIGINS = [ + 'https://oneskyit.com', + 'http://app-local.oneskyit.com', + 'http://192.168.32.20:3000', + 'http://192.168.32.20:8080', + + 'http://localhost', + 'http://localhost:3000', + 'http://localhost:5000', + 'http://localhost:8080', + 'http://localhost:7800', + + 'http://fastapi.localhost', + 'http://demo.localhost:5000', + + 'http://svelte.oneskyit.local:5555', + ] + + # HTTP Status Dict List HTTP_STATUS_LI = {} HTTP_STATUS_LI[200] = { 'name': 'OK', 'message': 'The request has succeeded.' } diff --git a/app/main.py b/app/main.py index 262d067..dd1d742 100644 --- a/app/main.py +++ b/app/main.py @@ -409,70 +409,13 @@ app.include_router( # BEGIN: CORS -# NOTE: Need to .localhost for less browser restrictions! Mainly for audio and video. -origins = [ - 'https://oneskyit.com', - 'http://app-local.oneskyit.com', - 'http://192.168.32.20:3000', - 'http://192.168.32.20:8080', - - 'http://localhost', - 'http://localhost:3000', - 'http://localhost:5000', - 'http://localhost:8080', - 'http://localhost:7800', - - 'http://fastapi.localhost', - - 'http://api.oneskyit.local:5000', - 'http://app.oneskyit.local:5000', - 'http://fastapi.oneskyit.local:5000', - 'http://svelte.oneskyit.local:5555', - - 'http://connect.localhost:5000', # Using localhost - 'http://connect.oneskyit.local:5000', - - 'http://demo.localhost:5000', # Using localhost - 'http://demo.oneskyit.local:5000', - - 'http://dev.localhost:5000', # Using localhost - 'http://dev.oneskyit.local:5000', - 'http://dev-app.oneskyit.local:5000', - 'http://dev-svelte.oneskyit.local:5555', - - 'http://dev-cmsc.oneskyit.local:5000', - 'http://dev-idaa.oneskyit.local:5000', - 'http://dev-ishlt.oneskyit.local:5000', - - 'http://cmsc.oneskyit.local:5000', - 'http://idaa.oneskyit.local:5000', - 'http://ishlt.oneskyit.local:5000', - 'http://businessgroup.oneskyit.local:5000', - 'http://aapor.oneskyit.local:5000', - - 'http://dev-ishlt.localhost:5000', # Using localhost - 'http://lci.localhost:5000', # Using localhost - 'http://ishlt.localhost:5000', # Using localhost - 'http://npa.localhost:5000', # Using localhost - - 'http://lci.internal:5000', # Using internal; just in case guess before LCI - 'http://lci.oneskyit.internal:5000', # Using internal; just in case guess before LCI - 'http://lci.oneskyit.internal', # Using internal; just in case guess before LCI - - 'http://lci.local:5000', # Using local; just in case guess before LCI - 'http://lci.oneskyit.local:5000', # Using local; just in case guess before LCI - 'http://lci.oneskyit.local', # Using local; just in case guess before LCI - - 'https://dev-api.oneskyit.com', - 'https://ishlt.oneskyit.com', - - 'http://cmsc.oneskyit.local', -] - +# NOTE: Need to include .localhost for less browser restrictions! Mainly for audio and video. app.add_middleware( CORSMiddleware, - allow_origins = origins, - allow_origin_regex = 'https://.*\.oneskyit\.com', + # allow_origins = origins, + allow_origins = config.settings.ORIGINS, + allow_origin_regex = config.settings.ORIGINS_REGEX, + # allow_origin_regex = 'https://.*\.oneskyit\.com', allow_credentials = True, allow_methods = ['*'], allow_headers = ['*'],