35 lines
788 B
Python
35 lines
788 B
Python
import fastapi
|
|
import uvicorn
|
|
import os
|
|
|
|
from app.routers import take
|
|
from app.routers import put
|
|
from app.routers import finish
|
|
|
|
from app.storage import mongo
|
|
|
|
|
|
QUEUES_TOKEN = os.getenv('QUEUES_TOKEN')
|
|
|
|
app = fastapi.FastAPI()
|
|
|
|
|
|
@app.middleware('http')
|
|
async def check_token(request: fastapi.Request, call_next):
|
|
if QUEUES_TOKEN:
|
|
token = request.headers.get('X-Queues-Token')
|
|
if not token or token != QUEUES_TOKEN:
|
|
return fastapi.JSONResponse(status_code=403, content={'message': 'token is not provided or incorrect'})
|
|
return await call_next(request)
|
|
|
|
|
|
app.include_router(take.router)
|
|
app.include_router(put.router)
|
|
app.include_router(finish.router)
|
|
|
|
mongo.create_indexes()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
uvicorn.run(app, host="0.0.0.0", port=1238)
|