Skip to content

Commit 3f39336

Browse files
committed
fixed urls sometimes not using localhost in testing
1 parent 8e9e276 commit 3f39336

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

core/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class SiteConfig(Config):
1212
DISCORD_CLIENT_SECRET = os.getenv('DISCORD_CLIENT_SECRET')
1313
PORT = int(os.getenv('PORT', 4000))
1414
DOMAIN = 'sharpbit.dev' if not DEV else f'127.0.0.1:{PORT}'
15+
BASE_URL = f"http{'s' if not DEV else ''}://{DOMAIN}"
1516
DB_USERNAME = os.getenv('DB_USERNAME')
1617
DB_PASSWORD = os.getenv('DB_PASSWORD')
1718
DB_NAME = os.getenv('DB_NAME')

core/routes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ async def dashboard_home(request: Request):
8282
request=request,
8383
title="Dashboard",
8484
description='Dashboard for your account.',
85+
base_url=request.app.config.BASE_URL,
8586
urls=urls,
8687
pastes=pastes
8788
)
@@ -108,12 +109,11 @@ async def create_url(request: Request):
108109
if existing:
109110
return add_message(request, 'error', 'That code is already taken. Try another one.', '/urlshortener')
110111
await conn.execute('INSERT INTO urls(user_id, code, url) VALUES ($1, $2, $3)', account, code, url)
111-
secure = 's' if not request.app.config.DEV else ''
112112
return add_message(
113113
request,
114114
'success',
115-
f"Shortened URL created at <a href=\"http{secure}://{request.app.config.DOMAIN}/{code}\">"
116-
f"http{'s' if not request.app.config.DEV else ''}://{request.app.config.DOMAIN}/{code}</a>",
115+
f"Shortened URL created at <a href=\"{request.app.config.BASE_URL}/{code}\">"
116+
f"{request.app.config.BASE_URL}/{code}</a>",
117117
'/urlshortener'
118118
)
119119

core/templates/dashboard.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ <h1 style="padding-top:20px">Dashboard</h1>
44
<div class="content-section" style="padding-bottom:20px">
55
<h3>Shortened URLs</h3>
66
{% for url in urls %}
7-
<a href="{{ url.url }}">https://sharpbit.dev/{{ url.code }}</a><br />
7+
<a href="{{ url.url }}">{{ base_url }}/{{ url.code }}</a><br />
88
{% endfor %}
99
</div>
1010
<div class="content-section" style="padding-bottom:20px">
1111
<h3>Pastebins</h3>
1212
{% for p in pastes %}
13-
<a href="https://sharpbit.dev/pastebin/{{ p.code }}">https://sharpbit.dev/pastebin/{{ p.code }}</a><br />
13+
<a href="{{ base_url }}/pastebin/{{ p.code }}">{{ base_url }}/pastebin/{{ p.code }}</a><br />
1414
{% endfor %}
1515
</div>
1616
{% endblock content %}

0 commit comments

Comments
 (0)