Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The app which fulfills the following requirements for a
- Debug by starting F5 in VSCode (Starting chrome also)
- Deployment of a productive version with precompiled frontend server
- Deployment to Azure App Service Free Plan with Actions on Pull Request
- Handle Front and Backend routing in FastAPI both together

## Prerequisites
Here are the prerequisites that you have to install before running the app
Expand All @@ -30,6 +31,8 @@ python -m venv venv
.\venv\Scripts\activate.bat
pip install -r requirements.txt
```
5. Go into the frontend folder `cd ./frontend`
6. Run `npm install` which will download and install all frontend packages
### Architecture
Here is the simple architecture description
#### ./backend
Expand Down
43 changes: 18 additions & 25 deletions backend/main.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,31 @@
from fastapi import FastAPI, APIRouter
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
from os import path as os_path

from fastapi.responses import FileResponse, RedirectResponse
from pathlib import Path
# Init FastAPI
app = FastAPI()
origins = ["http://localhost:5173", "localhost:5173"]
app.add_middleware(CORSMiddleware,allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"])

origins = [
"http://localhost:5173",
"localhost:5173"
]

app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"]
)

# API Router
api_router = APIRouter()

@api_router.get("/hello")
def read_hello():
return {"message": "Hello from API"}

app.include_router(api_router, prefix="/api")

# Mount static files on /static (adjust if you want a different prefix)
app.mount("", StaticFiles(directory="./dist", html=True), name="client")

# Optional: Serve index.html at the root
@app.get('/')
async def client(): return RedirectResponse(url="client")

# Frontend Router
dist = Path("./dist")
frontend_router = APIRouter()
@frontend_router.get('/{path:path}')
async def frontend_handler(path: str):
fp = dist / path
if path == '' or not fp.exists():
fp = dist / "index.html"
return FileResponse(fp)
app.include_router(frontend_router, prefix="")

# Bootstrap the app
if __name__ == '__main__':
uvicorn.run('main:app', reload=True)
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React</title>
<title>EntraID-Web-Auth-Reference</title>
</head>
<body>
<div id="root"></div>
Expand Down
Loading