diff --git a/library_service/routers/misc.py b/library_service/routers/misc.py index 4c4e2ec..674dfa6 100644 --- a/library_service/routers/misc.py +++ b/library_service/routers/misc.py @@ -96,10 +96,10 @@ async def book(request: Request, book_id: int): return templates.TemplateResponse(request, "book.html") - @router.get("/auth", include_in_schema=False) - async def auth(request: Request): - """Эндпоинт страницы авторизации""" - return templates.TemplateResponse(request, "auth.html") +@router.get("/auth", include_in_schema=False) +async def auth(request: Request): + """Эндпоинт страницы авторизации""" + return templates.TemplateResponse(request, "auth.html") @router.get("/profile", include_in_schema=False) diff --git a/library_service/static/utils.js b/library_service/static/utils.js index 678f51e..369ebe7 100644 --- a/library_service/static/utils.js +++ b/library_service/static/utils.js @@ -53,7 +53,12 @@ const Utils = { }; const Api = { + getBaseUrl() { + return window.location.origin; + }, + async request(endpoint, options = {}) { + const fullUrl = this.getBaseUrl() + endpoint; const token = localStorage.getItem("access_token"); const headers = { "Content-Type": "application/json", @@ -67,14 +72,14 @@ const Api = { const config = { ...options, headers }; try { - const response = await fetch(endpoint, config); + const response = await fetch(fullUrl, config); if (response.status === 401) { const refreshed = await Auth.tryRefresh(); if (refreshed) { headers["Authorization"] = `Bearer ${localStorage.getItem("access_token")}`; - const retryResponse = await fetch(endpoint, { ...options, headers }); + const retryResponse = await fetch(fullUrl, { ...options, headers }); if (retryResponse.ok) { return retryResponse.json(); }