Skip to content

Commit

Permalink
Working API with vercel (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinebou12 committed Sep 23, 2023
1 parent 3e40e8b commit d7ce4a9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,4 @@ dmypy.json
.pyre/

*/raw
.vercel
16 changes: 0 additions & 16 deletions api/Pipfile

This file was deleted.

15 changes: 8 additions & 7 deletions api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from fastapi.security import HTTPBasic, HTTPBasicCredentials
from jose import JWTError, jwt
from datetime import datetime, timedelta
from cryptography.hazmat.primitives import asymmetric, hashes, serialization
from cryptography.hazmat.backends import default_backend
import base64
import os

# import sys
Expand All @@ -17,7 +12,9 @@

# Initialize FastAPI and Jinja2
app = FastAPI(docs_url="/docs", redoc_url=None)
templates=Jinja2Templates(directory="templates")

current_directory = os.path.dirname(os.path.abspath(__file__))
templates=Jinja2Templates(directory=os.path.join(current_directory, "templates"))

app.add_middleware(
CORSMiddleware,
Expand All @@ -38,6 +35,10 @@ async def get_current_user(credentials: HTTPBasicCredentials = Depends(security)
# Log the error here if you want
raise HTTPException(status_code=401, detail="MarketWatch validation failed")

@app.get("/")
def read_root(request: Request):
return "Marketwatch API"

@app.get("/game/{game_id}", response_class=HTMLResponse)
async def game(request: Request, game_id: str, mw: MarketWatch = Depends(get_current_user)):
data = mw.get_game(game_id=game_id)
Expand All @@ -61,4 +62,4 @@ async def card(request: Request, game_id: str, mw: MarketWatch = Depends(get_cur
@app.get("/watchlist/{watchlist_id}", response_class=HTMLResponse)
async def watchlists(request: Request, watchlist_id: str, mw: MarketWatch = Depends(get_current_user)):
data = mw.get_watchlist(watchlist_id=watchlist_id)
return templates.TemplateResponse("watchlists.html.j2", {"request": request, "data": data})
return templates.TemplateResponse("watchlists.html.j2", {"request": request, "data": data})
3 changes: 1 addition & 2 deletions api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ uvicorn
httpx
marketwatch
jinja2
python-jose
pydantic
marketwatch
marketwatch
21 changes: 0 additions & 21 deletions api/vercel.json

This file was deleted.

20 changes: 20 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": 2,
"builds": [
{
"src": "api/app.py",
"use": "@vercel/python",
"config": {
"buildCommand": "pip install --upgrade pip && cd api && pip install -r requirements.txt && uvicorn app:app --host 0.0.0.0 --port 3000",
"debug": true
}
}
],
"routes": [
{
"src": "/(.*)",
"dest": "api/app.py"
}
]
}

0 comments on commit d7ce4a9

Please sign in to comment.