# standard imports import logging from urllib.parse import urlparse import redis from cic_eth.server import args, cache, config, openapi, routes # define log levels if args.vv: logging.getLogger().setLevel(logging.DEBUG) elif args.v: logging.getLogger().setLevel(logging.INFO) log = logging.getLogger(__name__) # TODO Censor relevant things log.debug(f"{config}") # define universal redis cache access cache.Cache.store = redis.StrictRedis(host=config.get('REDIS_HOST'), port=config.get('REDIS_PORT'), db=config.get('REDIS_DB'), decode_responses=True) # uwsgi application def application(env, start_response): # Validate incoming request against the open api spec errors, request = openapi.validate.request(env, start_response) if errors: return errors parsed_url = urlparse(env.get('REQUEST_URI')) path = parsed_url.path query = dict(request.parameters.query) handler = routes.get(path) if handler: return handler(start_response, query) start_response('404 This is not the path you\'re looking for', []) return []