mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2025-07-12 09:42:16 +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.curd import get_link_by_slug, LinkNotFoundException
|
||||||
from redirect.db.dependency import get_db
|
from redirect.db.dependency import get_db
|
||||||
|
from redirect.settings import settings
|
||||||
|
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")
|
||||||
django.setup()
|
django.setup()
|
||||||
|
@ -57,15 +57,15 @@ def redirect(
|
||||||
if '+' in slug:
|
if '+' in slug:
|
||||||
return RedirectResponse(url=f'/tools/shortener/p/{slug.replace("+", "")}')
|
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(
|
save_view_meta.apply_async(
|
||||||
kwargs={
|
kwargs={
|
||||||
"pk": link[0],
|
"pk": link_id,
|
||||||
"ip": request.client.host,
|
"ip": request.client.host,
|
||||||
"user_agent": user_agent,
|
"user_agent": user_agent,
|
||||||
"token": sessionid,
|
"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_slug_cutoff: int = 3
|
||||||
|
|
||||||
redirect_host: str = "localhost"
|
relative_base: str = "http://127.0.0.1:8000"
|
||||||
redirect_port: int = 8000
|
|
||||||
redirect_reload: bool = False
|
|
||||||
|
|
||||||
database_url: str = "postgresql://postgres:postgres@127.0.0.1:5432/akarpov"
|
database_url: str = "postgresql://postgres:postgres@127.0.0.1:5432/akarpov"
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user