async def req1(req): print("req1", req.url) if '/get/' in req.path or '/do/' in req.path or '/post/' in req.path: return ext = req.path.split('.')[-1] if ext in ('mp3', 'js', 'jpg', 'css', 'ttf', 'png', 'woff', 'woff2', 'ico', 'gif', 'map', 'mem', 'pck', 'mp4', 'csv'): pfil = './web' + req.path return await response_file( location=pfil, headers={"cache-control": "public,max-age=216000"}) elif ext in 'html': pfil = './web' + req.path tmp = Render(pfil) rtn = await tmp.parse() return response_html( body=rtn, headers={"cache-control": "public,max-age=216000"}) elif ext in 'py': pfil = '.' + req.path # /w*.py y /vs_widgets will be served not server side .py if (req.path[:2] == '/w' or "/vs_widgets" in req.path) and ".." not in req.path: return await response_file( pfil, headers={"cache-control": "public,max-age=216000"}) else: return response_text("error") else: return response_text("error")
async def info(request): """Return an HTML page with a list of all add-ons.""" addons = '' with _LOCK: for addon in sorted(_LIST, key=lambda e: e['name']): addons += _LI_TEMPLATE.format( name=escape_html(addon['name']), description=escape_html(addon['description']), author=escape_html(addon['author']), homepage=escape_html(addon['homepage_url']), ) return response_html(_HTML.format(css=_CSS, addons=addons))
async def route1(req, tag): print(req) print('module', tag) print('params', req.raw_args) if '&' in tag: module = tag.split('&')[0] else: module = tag pfil = './web/' + module + '.html' tmp = Render(pfil) rtn = await tmp.parse() return response_html(body=rtn, headers={"cache-control": "public,max-age=216000"})
async def index(request: Request): return response_html(open("./dist/index.html", "r").read())