mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2025-04-19 10:31:59 +03:00
Add base path for relative URLs
This commit is contained in:
parent
52bc034fe3
commit
743edd19ed
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue
Block a user