404
-Oops, we couldn’t find that page!
-- It seems DocuNova has misplaced the document you were looking for. Whether it got lost in the cloud or hidden between the files, don’t worry – we’ve got your back. -
- - ← Return Home - -diff --git a/app/auth.py b/app/auth.py index db3df500..c6a9f18b 100644 --- a/app/auth.py +++ b/app/auth.py @@ -1,5 +1,4 @@ # app/auth.py -# app/auth.py import os from functools import wraps diff --git a/app/frontend.py b/app/frontend.py index 9cc25798..ccbf9d9d 100644 --- a/app/frontend.py +++ b/app/frontend.py @@ -1,39 +1,30 @@ -# app/frontend.py (new file or inline in main.py) -from fastapi import APIRouter, Request, status -from fastapi.responses import FileResponse -from fastapi.staticfiles import StaticFiles -from app.auth import require_login +# app/frontend.py import os +from pathlib import Path +from fastapi import APIRouter, Request +from fastapi.templating import Jinja2Templates +from app.auth import require_login router = APIRouter() -# 1) Serve the folder that contains index.html, etc. -# e.g. "frontend" is relative to your project root -frontend_folder = os.path.join(os.path.dirname(__file__), "..", "frontend") +# Point templates_dir to "frontend/templates" +templates_dir = Path(__file__).parent.parent / "frontend" / "templates" +templates = Jinja2Templates(directory=str(templates_dir)) -# If you just want to serve the entire folder as static: -router.mount("/static", StaticFiles(directory=frontend_folder), name="static") +@router.get("/", include_in_schema=False) +async def serve_index(request: Request): + return templates.TemplateResponse("index.html", {"request": request}) -# 2) For the root route ("/"), return the index.html +@router.get("/about", include_in_schema=False) +async def serve_about(request: Request): + return templates.TemplateResponse("about.html", {"request": request}) -@router.get("/upload", response_class=FileResponse) +@router.get("/upload", include_in_schema=False) @require_login async def serve_upload(request: Request): - return os.path.join(frontend_folder, "upload.html") + return templates.TemplateResponse("upload.html", {"request": request}) -# 3) Serve favicon.ico from the frontend folder -@router.get("/favicon.ico", response_class=FileResponse) +@router.get("/favicon.ico", include_in_schema=False) def favicon(): - return os.path.join(frontend_folder, "favicon.ico") - -""" @router.exception_handler(404) -async def custom_404_handler(request: Request, exc): - return FileResponse("frontend/404.html", status_code=status.HTTP_404_NOT_FOUND) """ - -@router.get("/", response_class=FileResponse) -async def serve_index(request: Request): - return os.path.join(frontend_folder, "index.html") - -@router.get("/about", response_class=FileResponse) -async def serve_about(request: Request): - return os.path.join(frontend_folder, "about.html") \ No newline at end of file + # If you have a real favicon in `frontend/static/favicon.ico`, you could do: + return str(Path(__file__).parent.parent / "frontend" / "static" / "favicon.ico") diff --git a/app/main.py b/app/main.py index d255c451..16c6c6e3 100644 --- a/app/main.py +++ b/app/main.py @@ -3,10 +3,14 @@ import os from fastapi import FastAPI, HTTPException, UploadFile, File, status, Request from fastapi.responses import FileResponse +from fastapi.staticfiles import StaticFiles +from fastapi.templating import Jinja2Templates from starlette.middleware.sessions import SessionMiddleware from starlette.config import Config from starlette.middleware.trustedhost import TrustedHostMiddleware from uvicorn.middleware.proxy_headers import ProxyHeadersMiddleware +from pathlib import Path + from app.database import init_db from app.config import settings from app.tasks.upload_to_s3 import upload_to_s3 @@ -14,13 +18,11 @@ from app.tasks.upload_to_dropbox import upload_to_dropbox from app.tasks.upload_to_paperless import upload_to_paperless from app.tasks.upload_to_nextcloud import upload_to_nextcloud from app.tasks.send_to_all import send_to_all_destinations -from pathlib import Path from app.api import router as api_router from app.frontend import router as frontend_router from app.auth import router as auth_router - # Load configuration from .env for the session key config = Config(".env") SESSION_SECRET = config( @@ -30,12 +32,10 @@ SESSION_SECRET = config( app = FastAPI(title="Document Processing API") - # 1) Session Middleware (for request.session to work) app.add_middleware(SessionMiddleware, secret_key=SESSION_SECRET) # 2) Respect the X-Forwarded-* headers from Traefik -# so your request.url_for(...) uses https://docparse.hosterra.net app.add_middleware(ProxyHeadersMiddleware, trusted_hosts="*") # 3) (Optional but recommended) Restrict valid hosts: @@ -45,12 +45,14 @@ app.add_middleware(TrustedHostMiddleware, allowed_hosts=[ "127.0.0.1" ]) +# Mount the static folder for CSS/JS: +frontend_static_dir = Path(__file__).parent.parent / "frontend" / "static" +app.mount("/static", StaticFiles(directory=frontend_static_dir), name="static") + @app.on_event("startup") def on_startup(): init_db() # Create tables if they don't exist - - @app.post("/process/") def process(file_path: str): """ @@ -166,10 +168,15 @@ async def ui_upload(file: UploadFile = File(...)): task = upload_to_s3.delay(target_path) return {"task_id": task.id, "status": "queued"} +# Custom 404 - we can still return the Jinja2 template, or the old static file: +# For a dynamic 404 using the base layout, see "frontend/404.html" usage below: @app.exception_handler(404) async def custom_404_handler(request: Request, exc: HTTPException): - return FileResponse( - "/app/frontend/404.html", + # Serve the 404 template directly + templates = Jinja2Templates(directory=str(frontend_static_dir.parent / "templates")) + return templates.TemplateResponse( + "404.html", + {"request": request}, status_code=status.HTTP_404_NOT_FOUND ) @@ -177,4 +184,3 @@ async def custom_404_handler(request: Request, exc: HTTPException): app.include_router(frontend_router) app.include_router(auth_router) app.include_router(api_router, prefix="/api") - diff --git a/frontend/404.html b/frontend/404.html deleted file mode 100644 index c085430d..00000000 --- a/frontend/404.html +++ /dev/null @@ -1,93 +0,0 @@ - - -
- -- It seems DocuNova has misplaced the document you were looking for. Whether it got lost in the cloud or hidden between the files, don’t worry – we’ve got your back. -
- - ← Return Home - -- Welcome to DocuNova – your modern, intelligent solution for document processing! We’ve built DocuNova to completely transform the way you handle your documents – from upload to extraction, from processing to storage. With cutting-edge technologies and a user-first design, DocuNova makes managing your documents as easy as a click. -
- - -- DocuNova was created with one goal in mind: to simplify and streamline document management for everyone, whether you’re a small startup or a large enterprise. Tired of clunky, outdated systems, we set out to design a platform that is intuitive, flexible, and packed with powerful features. -
-- We harness the power of OpenAI for metadata extraction and text refinement, integrate seamlessly with Dropbox, Nextcloud, and Paperless NGX for storage and indexing, leverage Azure Document Intelligence for OCR, and even use Gotenberg for file-to-PDF conversions. And while we’ve implemented AWS S3 for now, we’re always evolving! -
-- DocuNova is passionately developed by Christian Krakau-Louis, 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. -
-- Want to dive into the code, contribute ideas, or simply check out the magic behind DocuNova? Visit our GitHub repository to see the project in action! -
- -
- View DocuNova on GitHub
-
- - Your intelligent solution for processing, managing, and organizing documents effortlessly. -
- -- Quickly upload and process your files with our user-friendly interface. -
- - Get Started → - -- View, organize, and collaborate on your processed files in one central hub. -
- - View Files → - -+ It seems DocuNova has misplaced the document you were looking for. Don’t worry – we’ve got your back. +
+ + ← Return Home + ++ Welcome to DocuNova – your modern, intelligent solution for document processing! + We’ve built DocuNova to completely transform the way you handle your documents – from upload + to extraction, from processing to storage. +
+ + ++ DocuNova was created with one goal in mind: to simplify and streamline document management + for everyone, whether you’re a small startup or a large enterprise. +
++ We harness the power of OpenAI for metadata extraction and text refinement, integrate seamlessly + with Dropbox, Nextcloud, and Paperless NGX for storage and indexing, leverage Azure Document + Intelligence for OCR, and even use Gotenberg for file-to-PDF conversions. +
++ DocuNova is passionately developed by + Christian Krakau-Louis. +
++ Want to dive into the code, contribute ideas, or simply check out the magic behind DocuNova? + Visit our GitHub repository! +
+ +
+ View DocuNova on GitHub
+
+ + Your intelligent solution for processing, managing, and organizing documents effortlessly. +
+ ++ Quickly upload and process your files with our user-friendly interface. +
+ + Get Started → + ++ View, organize, and collaborate on your processed files in one central hub. +
+ + View Files → + ++ Drag & drop a file here, or click to select a file. +
+ +- Drag & drop a file here, or click to select a file. -
- -