ngay 2-8-2022
This commit is contained in:
20
app/main.py
Normal file → Executable file
20
app/main.py
Normal file → Executable file
@@ -1,25 +1,26 @@
|
||||
#===================== Importing FastAPI necessary packages =============
|
||||
# ===================== Importing FastAPI necessary packages =============
|
||||
from fastapi import (
|
||||
FastAPI,
|
||||
HTTPException,
|
||||
status,
|
||||
Request,
|
||||
)
|
||||
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from src.dependecies import authenticate_user
|
||||
from src.routers.routers import router
|
||||
from src.routers.post import post
|
||||
from src.routers.history_find import history
|
||||
from src.routers.post_save import post_save
|
||||
|
||||
import base64
|
||||
import binascii
|
||||
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
#------------------ FastAPI variable ----------------------------------
|
||||
# ------------------ FastAPI variable ----------------------------------
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
app.mount("/post", StaticFiles(directory="post"), name="post")
|
||||
|
||||
origins = ["*"]
|
||||
|
||||
@@ -33,13 +34,13 @@ app.add_middleware(
|
||||
|
||||
|
||||
# ================ Authentication Middleware =======================
|
||||
#----------- Here authentication is based on basic scheme,
|
||||
#----------- another authentication, based on bearer scheme, is used throughout
|
||||
#---------- the application (as decribed in FastAPI oficial documentation)
|
||||
# ----------- Here authentication is based on basic scheme,
|
||||
# ----------- another authentication, based on bearer scheme, is used throughout
|
||||
# ---------- the application (as decribed in FastAPI oficial documentation)
|
||||
@app.middleware("http")
|
||||
async def authenticate(request: Request, call_next):
|
||||
|
||||
#-------------------- Authentication basic scheme -----------------------------
|
||||
# -------------------- Authentication basic scheme -----------------------------
|
||||
if "Authorization" in request.headers:
|
||||
auth = request.headers["Authorization"]
|
||||
try:
|
||||
@@ -60,4 +61,5 @@ async def authenticate(request: Request, call_next):
|
||||
# ================= Routers inclusion from src directory ===============
|
||||
app.include_router(post)
|
||||
app.include_router(router)
|
||||
app.include_router(history)
|
||||
app.include_router(history)
|
||||
app.include_router(post_save)
|
||||
|
||||
Reference in New Issue
Block a user