Skip to content

Commit

Permalink
chore: update deps and example
Browse files Browse the repository at this point in the history
  • Loading branch information
long2ice committed May 20, 2024
1 parent 08501d1 commit e4a4cd5
Show file tree
Hide file tree
Showing 2 changed files with 749 additions and 669 deletions.
47 changes: 25 additions & 22 deletions examples/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,29 @@
)


@asynccontextmanager
async def lifespan(app: FastAPI):
r = redis.from_url(
settings.REDIS_URL,
decode_responses=True,
encoding="utf8",
)
await admin_app.configure(
logo_url="https://preview.tabler.io/static/logo-white.svg",
template_folders=[os.path.join(BASE_DIR, "templates")],
favicon_url="https://raw.githubusercontent.com/fastapi-admin/fastapi-admin/dev/images/favicon.png",
providers=[
LoginProvider(
login_logo_url="https://preview.tabler.io/static/logo.svg",
admin_model=Admin,
)
],
redis=r,
)


def create_app():
app = FastAPI()
app = FastAPI(lifespan=lifespan)
app.mount(
"/static",
StaticFiles(directory=os.path.join(BASE_DIR, "static")),
Expand All @@ -39,31 +60,13 @@ def create_app():
async def index():
return RedirectResponse(url="/admin")

admin_app.add_exception_handler(HTTP_500_INTERNAL_SERVER_ERROR, server_error_exception)
admin_app.add_exception_handler(
HTTP_500_INTERNAL_SERVER_ERROR, server_error_exception
)
admin_app.add_exception_handler(HTTP_404_NOT_FOUND, not_found_error_exception)
admin_app.add_exception_handler(HTTP_403_FORBIDDEN, forbidden_error_exception)
admin_app.add_exception_handler(HTTP_401_UNAUTHORIZED, unauthorized_error_exception)

@app.on_event("startup")
async def startup():
r = redis.from_url(
settings.REDIS_URL,
decode_responses=True,
encoding="utf8",
)
await admin_app.configure(
logo_url="https://preview.tabler.io/static/logo-white.svg",
template_folders=[os.path.join(BASE_DIR, "templates")],
favicon_url="https://raw.githubusercontent.com/fastapi-admin/fastapi-admin/dev/images/favicon.png",
providers=[
LoginProvider(
login_logo_url="https://preview.tabler.io/static/logo.svg",
admin_model=Admin,
)
],
redis=r,
)

app.mount("/admin", admin_app)
app.add_middleware(
CORSMiddleware,
Expand Down
Loading

0 comments on commit e4a4cd5

Please sign in to comment.