make possible for the admin to change server's name and host in .env

This commit is contained in:
sunwoo1524 2024-05-05 16:03:06 +09:00
parent 258e4f8b55
commit c2495565d9
6 changed files with 27 additions and 4 deletions

View file

@ -1,3 +1,6 @@
NAME=Krll
HOST=https://krll.me
POSTGRES_HOST=db:5432 POSTGRES_HOST=db:5432
POSTGRES_DATABASE=postgres POSTGRES_DATABASE=postgres
POSTGRES_USER=postgres POSTGRES_USER=postgres

17
main.py
View file

@ -8,6 +8,11 @@ from src.database import engine
from src import models from src import models
from src.routes.url import url_route 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) models.Base.metadata.create_all(bind=engine)
@ -32,12 +37,20 @@ app.mount("/static", StaticFiles(directory="./static"), name="static")
@app.get("/", response_class=HTMLResponse) @app.get("/", response_class=HTMLResponse)
def index(request: Request): 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) @app.get("/about", response_class=HTMLResponse)
def about(request: Request): 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) app.include_router(url_route.routes)

View file

@ -4,6 +4,9 @@ import os
load_dotenv() load_dotenv()
NAME = os.environ.get("NAME")
HOST = os.environ.get("HOST")
POSTGRES_DATABASE = os.environ.get("POSTGRES_DATABASE") POSTGRES_DATABASE = os.environ.get("POSTGRES_DATABASE")
POSTGRES_USER = os.environ.get("POSTGRES_USER") POSTGRES_USER = os.environ.get("POSTGRES_USER")
POSTGRES_PASSWORD = os.environ.get("POSTGRES_PASSWORD") POSTGRES_PASSWORD = os.environ.get("POSTGRES_PASSWORD")

View file

@ -45,7 +45,7 @@ const shorten = async () => {
} }
const data = await response.json(); const data = await response.json();
const result = `https://krll.me/${data.key}` const result = `${host}/${data.key}`;
// show the short url // show the short url
short_url.innerText = result; short_url.innerText = result;

View file

@ -21,5 +21,9 @@
</div> </div>
</main> </main>
<script>
const host = "{{ host }}";
</script>
<script src="{{ url_for('static', path='/script.js') }}"></script> <script src="{{ url_for('static', path='/script.js') }}"></script>
{% endblock %} {% endblock %}

View file

@ -14,7 +14,7 @@
<footer> <footer>
<p>스팸이나 불법적인 용도로 사용하지 말아주세요.</p> <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> </footer>
</body> </body>
</html> </html>