Compare commits
1 Commits
09196e99b1
...
57baf8d2fb
Author | SHA1 | Date | |
---|---|---|---|
57baf8d2fb |
@ -29,7 +29,9 @@ async def handle_request(request: Request):
|
|||||||
path = request.path_params["path"]
|
path = request.path_params["path"]
|
||||||
short_url = await shortUrlDao.find_single_by({ShortUrl.short_url: path})
|
short_url = await shortUrlDao.find_single_by({ShortUrl.short_url: path})
|
||||||
if short_url is None:
|
if short_url is None:
|
||||||
return templates.TemplateResponse("404.html", {"request": request}, status_code=404)
|
return templates.TemplateResponse(
|
||||||
|
"404.html", {"request": request}, status_code=404
|
||||||
|
)
|
||||||
|
|
||||||
domains = Environment.get("DOMAINS", list[str], [])
|
domains = Environment.get("DOMAINS", list[str], [])
|
||||||
domain = await short_url.domain
|
domain = await short_url.domain
|
||||||
@ -43,10 +45,12 @@ async def handle_request(request: Request):
|
|||||||
|
|
||||||
domain_strict_mode = Environment.get("DOMAIN_STRICT_MODE", bool, False)
|
domain_strict_mode = Environment.get("DOMAIN_STRICT_MODE", bool, False)
|
||||||
if domain is not None and (
|
if domain is not None and (
|
||||||
domain.name not in domains
|
domain.name not in domains
|
||||||
or (domain_strict_mode and not host.endswith(domain.name))
|
or (domain_strict_mode and not host.endswith(domain.name))
|
||||||
):
|
):
|
||||||
return templates.TemplateResponse("404.html", {"request": request}, status_code=404)
|
return templates.TemplateResponse(
|
||||||
|
"404.html", {"request": request}, status_code=404
|
||||||
|
)
|
||||||
|
|
||||||
user_agent = request.headers.get("User-Agent", "").lower()
|
user_agent = request.headers.get("User-Agent", "").lower()
|
||||||
|
|
||||||
@ -58,7 +62,11 @@ async def handle_request(request: Request):
|
|||||||
|
|
||||||
return templates.TemplateResponse(
|
return templates.TemplateResponse(
|
||||||
"redirect.html",
|
"redirect.html",
|
||||||
{"request": request, "key": short_url.short_url, "target_url": _get_redirect_url(short_url.target_url)},
|
{
|
||||||
|
"request": request,
|
||||||
|
"key": short_url.short_url,
|
||||||
|
"target_url": _get_redirect_url(short_url.target_url),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
return await _handle_short_url(request, path, short_url)
|
return await _handle_short_url(request, path, short_url)
|
||||||
@ -99,7 +107,7 @@ async def configure():
|
|||||||
|
|
||||||
routes = [
|
routes = [
|
||||||
Route("/", endpoint=index),
|
Route("/", endpoint=index),
|
||||||
Mount('/static', StaticFiles(directory='static'), name='static'),
|
Mount("/static", StaticFiles(directory="static"), name="static"),
|
||||||
Route("/{path:path}", endpoint=handle_request),
|
Route("/{path:path}", endpoint=handle_request),
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -121,4 +129,4 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user