You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.3 KiB
Python

4 years ago
import os
from django.core.wsgi import get_wsgi_application
from fastapi.middleware.cors import CORSMiddleware
4 years ago
from django.conf import settings
4 years ago
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "etebase_server.settings")
application = get_wsgi_application()
from fastapi import FastAPI, Request
from .execptions import CustomHttpException
from .authentication import authentication_router
4 years ago
from .collection import collection_router
4 years ago
from .msgpack import MsgpackResponse
app = FastAPI()
4 years ago
VERSION = "v1"
BASE_PATH = f"/api/{VERSION}"
app.include_router(authentication_router, prefix=f"{BASE_PATH}/authentication")
app.include_router(collection_router, prefix=f"{BASE_PATH}/collection")
4 years ago
if settings.DEBUG:
from .test_reset_view import test_reset_view_router
app.include_router(test_reset_view_router, prefix=f"{BASE_PATH}/test/authentication")
4 years ago
app.add_middleware(
CORSMiddleware, allow_origin_regex="https?://.*", allow_credentials=True, allow_methods=["*"], allow_headers=["*"]
)
@app.exception_handler(CustomHttpException)
async def custom_exception_handler(request: Request, exc: CustomHttpException):
return MsgpackResponse(status_code=exc.status_code, content=exc.as_dict)
if __name__ == "__main__":
import uvicorn
4 years ago
uvicorn.run(app, host="0.0.0.0", port=8000)