-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
48 lines (39 loc) · 1.34 KB
/
Copy pathapp.py
File metadata and controls
48 lines (39 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
import backend.todo as todo
import backend.service.payment as payment
# --- FastAPI App Setup ---
app = FastAPI(
title="Todo API",
description="A simple TODO API built with FastAPI",
version="1.0.0",
)
# Serve files in the `static` directory at the `/static` URL path
app.mount("/static", StaticFiles(directory="static"), name="static")
# Jinja2 templates for HTML pages
templates = Jinja2Templates(directory="templates")
# CORS middleware configuration
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include sub-routers for Todo and Payments
app.include_router(todo.router)
app.include_router(payment.router)
# --- Base Page Route ---
@app.get("/")
async def home(request: Request):
"""Serve the main HTML page."""
return templates.TemplateResponse(request=request, name="index.html", context={})
if __name__ == "__main__":
import uvicorn
# Get the port dynamically from the environment
port = int(os.environ.get("PORT", 8000))
# Bind to 0.0.0.0 so it is accessible from outside the container
uvicorn.run(app, host="0.0.0.0", port=port)