Add base path for relative URLs

This commit is contained in:
Damir Modyarov 2023-08-07 23:19:06 +03:00
parent 52bc034fe3
commit 743edd19ed
2 changed files with 5 additions and 8 deletions

View File

@ -9,7 +9,7 @@
from redirect.db.curd import get_link_by_slug, LinkNotFoundException
from redirect.db.dependency import get_db
from redirect.settings import settings
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")
django.setup()
@ -57,15 +57,15 @@ def redirect(
if '+' in slug:
return RedirectResponse(url=f'/tools/shortener/p/{slug.replace("+", "")}')
link = get_link_by_slug(db, slug)
link_id, link_target = get_link_by_slug(db, slug)
save_view_meta.apply_async(
kwargs={
"pk": link[0],
"pk": link_id,
"ip": request.client.host,
"user_agent": user_agent,
"token": sessionid,
},
)
return RedirectResponse(url=link[1])
return RedirectResponse(url=(settings.relative_base + link_target) if link_target.startswith('/') else link_target)

View File

@ -6,10 +6,7 @@ class AppSettings(BaseSettings):
redirect_slug_cutoff: int = 3
redirect_host: str = "localhost"
redirect_port: int = 8000
redirect_reload: bool = False
relative_base: str = "http://127.0.0.1:8000"
database_url: str = "postgresql://postgres:postgres@127.0.0.1:5432/akarpov"
class Config: