selfprivacy-rest-api/selfprivacy_api/app.py

47 lines
962 B
Python
Raw Normal View History

2021-11-11 20:31:28 +02:00
#!/usr/bin/env python3
2021-11-16 18:14:01 +02:00
"""SelfPrivacy server management API"""
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from strawberry.fastapi import GraphQLRouter
2021-12-06 08:48:29 +02:00
import uvicorn
2021-12-06 08:48:29 +02:00
from selfprivacy_api.dependencies import get_api_version
2022-06-24 20:12:32 +03:00
from selfprivacy_api.graphql.schema import schema
from selfprivacy_api.migrations import run_migrations
2022-06-24 16:05:18 +03:00
2021-11-11 20:31:28 +02:00
app = FastAPI()
2021-11-11 20:31:28 +02:00
graphql_app = GraphQLRouter(
schema,
)
2021-11-16 18:14:01 +02:00
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
2021-11-11 20:31:28 +02:00
app.include_router(graphql_app, prefix="/graphql")
2021-11-16 18:14:01 +02:00
@app.get("/api/version")
async def get_version():
"""Get the version of the server"""
return {"version": get_api_version()}
2022-06-24 16:05:18 +03:00
2021-11-16 18:14:01 +02:00
@app.on_event("startup")
async def startup():
run_migrations()
2021-11-11 20:31:28 +02:00
if __name__ == "__main__":
2022-08-26 20:01:14 +03:00
uvicorn.run(
"selfprivacy_api.app:app", host="127.0.0.1", port=5050, log_level="info"
)