-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (45 loc) · 1.66 KB
/
main.py
File metadata and controls
62 lines (45 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""Main REST API service wiring for MariaDB.
Author: Kamil 'Nowik' Nowicki <kamil.nowak85@icloud.com>
Copyright 2025
License: Apache License 2.0
"""
from fastapi import FastAPI, Request
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
from routes_auth import router as auth_router
from routes_admin import router as admin_router
from routes_tables import router as tables_router
from settings import SERVER_HOST, SERVER_PORT, logger
app = FastAPI(
title="MariaDB REST API",
description=(
"Simple REST API for MariaDB with role-based access control.\n\n"
"Normal users can only search data. Admins can create admins, and search, modify or delete data."
),
version="1.0.0",
)
# Mount static files (frontend) directory
app.mount("/static", StaticFiles(directory="static"), name="static")
@app.middleware("http")
async def log_requests(request: Request, call_next):
logger.info("%s %s", request.method, request.url.path)
try:
response = await call_next(request)
return response
except Exception:
logger.exception("Unhandled error in request %s %s", request.method, request.url.path)
raise
# Include modular routers
app.include_router(auth_router)
app.include_router(admin_router)
app.include_router(tables_router)
@app.get("/")
async def root():
return {"message": "MariaDB REST API is running"}
@app.get("/app")
async def web_app():
"""Serve the simple web frontend (HTML+JS) for browser access."""
return FileResponse("static/index.html")
if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", host=SERVER_HOST, port=SERVER_PORT, reload=False)