Gros refactoring
This commit is contained in:
parent
6008aa68f6
commit
4a6bfc951f
368 changed files with 22503 additions and 3 deletions
77
backend/main.py
Normal file
77
backend/main.py
Normal file
|
@ -0,0 +1,77 @@
|
|||
"""
|
||||
Fabrique à documents
|
||||
Copyright (C) 2023 François Pelletier
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import sys
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.testclient import TestClient
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from routers import users, images, generer, format_styles
|
||||
from responses import App
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
handlers=[
|
||||
logging.FileHandler("app.log"),
|
||||
logging.StreamHandler(sys.stdout)
|
||||
]
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
# Add CORS middleware
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"], # Allows all origins
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"], # Allows all methods
|
||||
allow_headers=["*"], # Allows all headers
|
||||
)
|
||||
|
||||
app.include_router(users.router)
|
||||
app.include_router(images.router, prefix="/images", tags=["images"])
|
||||
app.include_router(generer.router, prefix="/generer", tags=["generer"])
|
||||
app.include_router(format_styles.router, tags=["format_styles"])
|
||||
|
||||
@app.middleware("http")
|
||||
async def log_requests(request: Request, call_next):
|
||||
logger.info(f"Request: {request.method} {request.url}")
|
||||
response = await call_next(request)
|
||||
logger.info(f"Response status: {response.status_code}")
|
||||
return response
|
||||
|
||||
@app.get("/")
|
||||
async def get_root():
|
||||
logger.info("Root endpoint accessed")
|
||||
app = App(app='fabriquedoc')
|
||||
return app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
def test_getroot():
|
||||
response = client.get("/")
|
||||
assert response.status_code == 200
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
logger.info("Starting the application")
|
||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
Loading…
Add table
Add a link
Reference in a new issue