Compare commits
1 Commits
57baf8d2fb
...
09196e99b1
Author | SHA1 | Date | |
---|---|---|---|
09196e99b1 |
@ -29,9 +29,7 @@ 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(
|
return templates.TemplateResponse("404.html", {"request": request}, status_code=404)
|
||||||
"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
|
||||||
@ -45,12 +43,10 @@ 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(
|
return templates.TemplateResponse("404.html", {"request": request}, status_code=404)
|
||||||
"404.html", {"request": request}, status_code=404
|
|
||||||
)
|
|
||||||
|
|
||||||
user_agent = request.headers.get("User-Agent", "").lower()
|
user_agent = request.headers.get("User-Agent", "").lower()
|
||||||
|
|
||||||
@ -62,11 +58,7 @@ 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)
|
||||||
@ -107,7 +99,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),
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -129,4 +121,4 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
Loading…
Reference in New Issue
Block a user