def before_request():
g.res = LunabitResponse()
# all routes must have a trailing slash, will append if doesn't exist
if not request.path.endswith('/'):
request.path = ''.join([request.path, '/'])
# removing api version from beginning of string for proper routing
request_path = str(request.url_rule) if request.url_rule else request.path
url_rules = [r.rule for r in app.url_map.iter_rules()]
if request_path in url_rules:
for r in app.url_map.iter_rules():
if r.rule == request_path and request.method in r.methods:
print(r.methods)
try:
g.req = LunabitRequest.from_data(request.method, request)
g.user = g.req.user
break
except GridlightException as e:
raise InvalidUsage(message=str(e))
else:
err = ''.join(["URL '", request_path, "' does not allow the method '", request.method,"'."])
print_log(err)
raise InvalidUsage(message=err, status_code=405)
else:
err = ''.join(["URL '", request_path, "' does not exist."])
print_log(err)
raise InvalidUsage(message=err, status_code=404)
评论列表
文章目录