Skip to content

Commit

Permalink
refactor: move fastapi app init to main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
borolepratik committed Apr 18, 2024
1 parent 4c75153 commit 3843b6a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
26 changes: 0 additions & 26 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# External
import fastf1
from dotenv import dotenv_values
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.security import HTTPBearer
from fastf1.ergast import Ergast

Expand All @@ -33,27 +31,3 @@
favicon_path = "favicon.ico"
# Security
security = HTTPBearer()

app = FastAPI(
title="Slick Telemetry API",
description="Slick Telemetry backend written in python with fastf1. 🏎",
version=__version__,
contact={
"name": "Slick Telemetry",
"url": "https://github.com/Slick-Telemetry",
"email": "[email protected]",
},
license_info={
"name": "GNU General Public License v3.0",
"url": "https://www.gnu.org/licenses/gpl-3.0.en.html",
},
redoc_url=None,
)
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
# HTTPSRedirectMiddleware # TODO use for production and staging
)
30 changes: 28 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
from typing import Annotated, List

# External
from fastapi import Depends, HTTPException, Path, Query, status
from fastapi import Depends, FastAPI, HTTPException, Path, Query, status
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse
from fastapi.security import HTTPAuthorizationCredentials
from pandas import Timestamp

# App
from . import app, config, ergast, fastf1, favicon_path, security
from . import __version__, config, ergast, fastf1, favicon_path, origins, security
from .constants import (
DEFAULT_SESSION,
EVENT_SCHEDULE_DATETIME_DTYPE_LIST,
Expand Down Expand Up @@ -44,6 +45,31 @@
from .utils import get_default_year


app = FastAPI(
title="Slick Telemetry API",
description="Slick Telemetry backend written in python with fastf1. 🏎",
version=__version__,
contact={
"name": "Slick Telemetry",
"url": "https://github.com/Slick-Telemetry",
"email": "[email protected]",
},
license_info={
"name": "GNU General Public License v3.0",
"url": "https://www.gnu.org/licenses/gpl-3.0.en.html",
},
redoc_url=None,
)
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
# HTTPSRedirectMiddleware # TODO use for production and staging
)


def validate_token(credentials: HTTPAuthorizationCredentials = Depends(security)):
"""
Validates the token provided in the HTTP Authorization header.
Expand Down

0 comments on commit 3843b6a

Please sign in to comment.