Archived
1
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
lantern/lantern/route.py
2017-04-11 21:27:19 +01:00

21 lines
653 B
Python

from sanic.response import html
from lantern.handle import execute_handle
from lantern.error import error_response
from lantern.request import serialize_request
import os
def build_main_route(args):
handle = os.path.abspath(args.handler)
if not os.path.isfile(handle) or not os.access(handle, os.X_OK):
raise FileNotFoundError("Can't find handle at {}".format(handle))
async def main_route(request, path=None):
result = execute_handle(handle, serialize_request(request))
if result.exit_code != 0:
return error_response(result.error)
return html(result.html, status=200)
return main_route