fixed 404

This commit is contained in:
Christian Krakau-Louis
2025-03-25 22:11:44 +01:00
parent 426e3af0f6
commit ff1f6e042c
4 changed files with 104 additions and 56 deletions
+1 -5
View File
@@ -20,10 +20,6 @@ from app.api import router as api_router
from app.frontend import router as frontend_router from app.frontend import router as frontend_router
from app.auth import router as auth_router from app.auth import router as auth_router
BASE_DIR = Path(__file__).resolve().parent # this is /app in many Docker setups
FRONTEND_DIR = BASE_DIR / "frontend"
# Load configuration from .env for the session key # Load configuration from .env for the session key
config = Config(".env") config = Config(".env")
@@ -173,7 +169,7 @@ async def ui_upload(file: UploadFile = File(...)):
@app.exception_handler(404) @app.exception_handler(404)
async def custom_404_handler(request: Request, exc: HTTPException): async def custom_404_handler(request: Request, exc: HTTPException):
return FileResponse( return FileResponse(
FRONTEND_DIR / "404.html", "/app/frontend/404.html",
status_code=status.HTTP_404_NOT_FOUND status_code=status.HTTP_404_NOT_FOUND
) )
+23 -6
View File
@@ -50,18 +50,35 @@
</div> </div>
</footer> </footer>
<!-- JavaScript for Dynamic Auth Section --> <!-- JavaScript for dynamic auth section -->
<script> <script>
(async function checkAuth() { (async function checkAuth() {
try { try {
const resp = await fetch("/api/whoami"); const resp = await fetch("/api/whoami");
if (resp.ok) { if (resp.ok) {
const data = await resp.json(); const data = await resp.json();
document.getElementById("authSection").innerHTML = ` // data.picture is expected to be a Gravatar URL
<img src="${data.picture}" alt="User Avatar" class="inline-block h-8 w-8 rounded-full mr-2"> const authSection = document.getElementById("authSection");
Logged in as <strong>${data.email}</strong> authSection.innerHTML = '';
<a href="/logout" class="ml-4 text-blue-600 hover:text-blue-800">Logout</a>
`; const img = document.createElement('img');
img.src = data.picture;
img.alt = 'User Avatar';
img.className = 'inline-block h-8 w-8 rounded-full mr-2';
const textNode = document.createTextNode('Logged in as ');
const strong = document.createElement('strong');
strong.textContent = data.email;
const logoutLink = document.createElement('a');
logoutLink.href = '/logout';
logoutLink.className = 'ml-4 text-blue-600 hover:text-blue-800';
logoutLink.textContent = 'Logout';
authSection.appendChild(img);
authSection.appendChild(textNode);
authSection.appendChild(strong);
authSection.appendChild(logoutLink);
} else { } else {
document.getElementById("authSection").innerHTML = document.getElementById("authSection").innerHTML =
`<a href="/login" class="text-blue-600">Login</a>`; `<a href="/login" class="text-blue-600">Login</a>`;
+23 -6
View File
@@ -65,7 +65,7 @@
<section class="bg-white shadow rounded p-6 mb-8"> <section class="bg-white shadow rounded p-6 mb-8">
<h2 class="text-2xl font-semibold mb-2">Meet the Creator</h2> <h2 class="text-2xl font-semibold mb-2">Meet the Creator</h2>
<p class="text-gray-600"> <p class="text-gray-600">
DocuNova is passionately developed by <a href="https://christianlouis.de" target="_blank" class="text-blue-600 hover:underline">Christian Krakau-Louis</a>, a visionary committed to solving real-world challenges with innovative technology. His dedication and expertise ensure that every feature in DocuNova is crafted with you in mind. DocuNova is passionately developed by <a href="https://www.christianlouis.de" target="_blank" class="text-blue-600 hover:underline">Christian Krakau-Louis</a>, a visionary committed to solving real-world challenges with innovative technology. His dedication and expertise ensure that every feature in DocuNova is crafted with you in mind.
</p> </p>
</section> </section>
@@ -96,11 +96,28 @@
const resp = await fetch("/api/whoami"); const resp = await fetch("/api/whoami");
if (resp.ok) { if (resp.ok) {
const data = await resp.json(); const data = await resp.json();
document.getElementById("authSection").innerHTML = ` // data.picture is expected to be a Gravatar URL
<img src="${data.picture}" alt="User Avatar" class="inline-block h-8 w-8 rounded-full mr-2"> const authSection = document.getElementById("authSection");
Logged in as <strong>${data.email}</strong> authSection.innerHTML = '';
<a href="/logout" class="ml-4 text-blue-600 hover:text-blue-800">Logout</a>
`; const img = document.createElement('img');
img.src = data.picture;
img.alt = 'User Avatar';
img.className = 'inline-block h-8 w-8 rounded-full mr-2';
const textNode = document.createTextNode('Logged in as ');
const strong = document.createElement('strong');
strong.textContent = data.email;
const logoutLink = document.createElement('a');
logoutLink.href = '/logout';
logoutLink.className = 'ml-4 text-blue-600 hover:text-blue-800';
logoutLink.textContent = 'Logout';
authSection.appendChild(img);
authSection.appendChild(textNode);
authSection.appendChild(strong);
authSection.appendChild(logoutLink);
} else { } else {
document.getElementById("authSection").innerHTML = document.getElementById("authSection").innerHTML =
`<a href="/login" class="text-blue-600">Login</a>`; `<a href="/login" class="text-blue-600">Login</a>`;
+24 -6
View File
@@ -114,17 +114,35 @@
} }
} }
// Dynamic auth check using /api/whoami <!-- JavaScript for dynamic auth section -->
(async function checkAuth() { (async function checkAuth() {
try { try {
const resp = await fetch("/api/whoami"); const resp = await fetch("/api/whoami");
if (resp.ok) { if (resp.ok) {
const data = await resp.json(); const data = await resp.json();
document.getElementById("authSection").innerHTML = ` // data.picture is expected to be a Gravatar URL
<img src="${data.picture}" alt="User Avatar" class="inline-block h-8 w-8 rounded-full mr-2"> const authSection = document.getElementById("authSection");
Logged in as <strong>${data.email}</strong> authSection.innerHTML = '';
<a href="/logout" class="ml-4 text-blue-600 hover:text-blue-800">Logout</a>
`; const img = document.createElement('img');
img.src = data.picture;
img.alt = 'User Avatar';
img.className = 'inline-block h-8 w-8 rounded-full mr-2';
const textNode = document.createTextNode('Logged in as ');
const strong = document.createElement('strong');
strong.textContent = data.email;
const logoutLink = document.createElement('a');
logoutLink.href = '/logout';
logoutLink.className = 'ml-4 text-blue-600 hover:text-blue-800';
logoutLink.textContent = 'Logout';
authSection.appendChild(img);
authSection.appendChild(textNode);
authSection.appendChild(strong);
authSection.appendChild(logoutLink);
} else { } else {
document.getElementById("authSection").innerHTML = document.getElementById("authSection").innerHTML =
`<a href="/login" class="text-blue-600">Login</a>`; `<a href="/login" class="text-blue-600">Login</a>`;