From 8216dd0d4e6111530fb13357035fe885857a5dd5 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Thu, 24 Nov 2022 19:02:42 +0300 Subject: [PATCH] minors --- auth/authenticate.py | 3 ++- server.py | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/auth/authenticate.py b/auth/authenticate.py index a361b699..95695604 100644 --- a/auth/authenticate.py +++ b/auth/authenticate.py @@ -58,7 +58,8 @@ def login_required(func): async def wrap(parent, info: GraphQLResolveInfo, *args, **kwargs): # print('[auth.authenticate] login required for %r with info %r' % (func, info)) # debug only auth: AuthCredentials = info.context["request"].auth - print('[auth.authenticate] request auth data: %r' % auth) # debug only + if auth and auth.user_id: + print(auth) # debug only if not auth.logged_in: return {"error": auth.error_message or "Please login"} return await func(parent, info, *args, **kwargs) diff --git a/server.py b/server.py index 265bfed6..882ea1aa 100644 --- a/server.py +++ b/server.py @@ -48,6 +48,17 @@ log_settings = { } } +local_headers = [ + ("Access-Control-Allow-Methods", "GET, POST, OPTIONS, HEAD"), + ("Access-Control-Allow-Origin", "http://localhost:3000"), + ( + "Access-Control-Allow-Headers", + "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization", + ), + ("Access-Control-Expose-Headers", "Content-Length,Content-Range"), + ("Access-Control-Allow-Credentials", "true"), +] + if __name__ == "__main__": x = "" if len(sys.argv) > 1: @@ -56,27 +67,18 @@ if __name__ == "__main__": if os.path.exists(DEV_SERVER_STATUS_FILE_NAME): os.remove(DEV_SERVER_STATUS_FILE_NAME) - headers = [ - ("Access-Control-Allow-Methods", "GET, POST, OPTIONS, HEAD"), - ("Access-Control-Allow-Origin", "http://localhost:3000"), - ( - "Access-Control-Allow-Headers", - "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization", - ), - ("Access-Control-Expose-Headers", "Content-Length,Content-Range"), - ("Access-Control-Allow-Credentials", "true"), - ] want_reload = False if "reload" in sys.argv: print("MODE: DEV + RELOAD") want_reload = True else: print("MODE: DEV") + uvicorn.run( "main:dev_app", host="localhost", port=8080, - headers=headers, + headers=local_headers, # log_config=LOGGING_CONFIG, log_level=None, access_log=False, @@ -84,6 +86,7 @@ if __name__ == "__main__": ) # , ssl_keyfile="discours.key", ssl_certfile="discours.crt") elif x == "migrate": from migration import migrate + print("MODE: MIGRATE") migrate() else: