selfprivacy-rest-api/selfprivacy_api/app.py
2022-08-12 17:43:04 +04:00

57 lines
1.3 KiB
Python

#!/usr/bin/env python3
"""SelfPrivacy server management API"""
import os
from fastapi import FastAPI, Depends, Request, WebSocket, BackgroundTasks
from fastapi.middleware.cors import CORSMiddleware
from strawberry.fastapi import BaseContext, GraphQLRouter
import uvicorn
from selfprivacy_api.dependencies import get_api_version, get_graphql_context
from selfprivacy_api.graphql.schema import schema
from selfprivacy_api.migrations import run_migrations
from selfprivacy_api.restic_controller.tasks import init_restic
from selfprivacy_api.rest import (
system,
users,
api_auth,
services,
)
app = FastAPI()
graphql_app = GraphQLRouter(
schema,
context_getter=get_graphql_context,
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(system.router)
app.include_router(users.router)
app.include_router(api_auth.router)
app.include_router(services.router)
app.include_router(graphql_app, prefix="/graphql")
@app.get("/api/version")
async def get_version():
"""Get the version of the server"""
return {"version": get_api_version()}
@app.on_event("startup")
async def startup():
run_migrations()
init_restic()
if __name__ == "__main__":
uvicorn.run("app:app", host="0.0.0.0", port=5050, log_level="info")