make possible for the admin to change server's name and host in .env
This commit is contained in:
parent
258e4f8b55
commit
c2495565d9
|
@ -1,3 +1,6 @@
|
|||
NAME=Krll
|
||||
HOST=https://krll.me
|
||||
|
||||
POSTGRES_HOST=db:5432
|
||||
POSTGRES_DATABASE=postgres
|
||||
POSTGRES_USER=postgres
|
||||
|
|
17
main.py
17
main.py
|
@ -8,6 +8,11 @@ from src.database import engine
|
|||
from src import models
|
||||
from src.routes.url import url_route
|
||||
|
||||
from src.env import NAME, HOST
|
||||
|
||||
|
||||
DEFAULT_CONTEXT = { "name": NAME, "host": HOST }
|
||||
|
||||
|
||||
models.Base.metadata.create_all(bind=engine)
|
||||
|
||||
|
@ -32,12 +37,20 @@ app.mount("/static", StaticFiles(directory="./static"), name="static")
|
|||
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
def index(request: Request):
|
||||
return templates.TemplateResponse(request=request, name="index.html")
|
||||
return templates.TemplateResponse(
|
||||
request=request,
|
||||
name="index.html",
|
||||
context=DEFAULT_CONTEXT
|
||||
)
|
||||
|
||||
|
||||
@app.get("/about", response_class=HTMLResponse)
|
||||
def about(request: Request):
|
||||
return templates.TemplateResponse(request=request, name="about.html")
|
||||
return templates.TemplateResponse(
|
||||
request=request,
|
||||
name="about.html",
|
||||
context=DEFAULT_CONTEXT
|
||||
)
|
||||
|
||||
|
||||
app.include_router(url_route.routes)
|
||||
|
|
|
@ -4,6 +4,9 @@ import os
|
|||
|
||||
load_dotenv()
|
||||
|
||||
NAME = os.environ.get("NAME")
|
||||
HOST = os.environ.get("HOST")
|
||||
|
||||
POSTGRES_DATABASE = os.environ.get("POSTGRES_DATABASE")
|
||||
POSTGRES_USER = os.environ.get("POSTGRES_USER")
|
||||
POSTGRES_PASSWORD = os.environ.get("POSTGRES_PASSWORD")
|
||||
|
|
|
@ -45,7 +45,7 @@ const shorten = async () => {
|
|||
}
|
||||
|
||||
const data = await response.json();
|
||||
const result = `https://krll.me/${data.key}`
|
||||
const result = `${host}/${data.key}`;
|
||||
|
||||
// show the short url
|
||||
short_url.innerText = result;
|
||||
|
|
|
@ -21,5 +21,9 @@
|
|||
</div>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
const host = "{{ host }}";
|
||||
</script>
|
||||
|
||||
<script src="{{ url_for('static', path='/script.js') }}"></script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
<footer>
|
||||
<p>스팸이나 불법적인 용도로 사용하지 말아주세요.</p>
|
||||
<p><a href="/about">About Krll</a> · <a href="mailto:maengkkong1524@naver.com">Contact</a></p>
|
||||
<p><a href="/about">About {{ name }}</a> · <a href="mailto:maengkkong1524@naver.com">Contact</a></p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue