2023-07-05 19:12:57 +00:00
|
|
|
"""
|
|
|
|
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/>.
|
|
|
|
"""
|
|
|
|
|
2022-12-28 05:04:27 +00:00
|
|
|
import logging
|
2024-11-11 04:28:47 +00:00
|
|
|
import sys
|
|
|
|
from fastapi import FastAPI, Request
|
2022-12-28 05:04:27 +00:00
|
|
|
from fastapi.testclient import TestClient
|
2024-11-11 04:28:47 +00:00
|
|
|
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)
|
|
|
|
]
|
|
|
|
)
|
2023-02-12 06:04:11 +00:00
|
|
|
|
2024-11-11 04:28:47 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2023-02-12 06:04:11 +00:00
|
|
|
|
2024-08-24 02:50:28 +00:00
|
|
|
app = FastAPI()
|
2023-02-12 06:04:11 +00:00
|
|
|
|
2024-11-11 04:28:47 +00:00
|
|
|
# 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
|
2023-01-22 00:12:08 +00:00
|
|
|
|
2023-01-05 03:18:29 +00:00
|
|
|
@app.get("/")
|
|
|
|
async def get_root():
|
2024-11-11 04:28:47 +00:00
|
|
|
logger.info("Root endpoint accessed")
|
2023-01-05 03:18:29 +00:00
|
|
|
app = App(app='fabriquedoc')
|
|
|
|
return app
|
|
|
|
|
2022-12-28 05:04:27 +00:00
|
|
|
client = TestClient(app)
|
|
|
|
|
2023-01-22 00:12:08 +00:00
|
|
|
def test_getroot():
|
|
|
|
response = client.get("/")
|
2022-12-28 05:04:27 +00:00
|
|
|
assert response.status_code == 200
|
2024-11-11 04:28:47 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import uvicorn
|
|
|
|
logger.info("Starting the application")
|
|
|
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|