-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move fastapi app init to main.py
- Loading branch information
1 parent
4c75153
commit 3843b6a
Showing
2 changed files
with
28 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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. | ||
|