Initial commits
This commit is contained in:
55
backend/main.py
Normal file
55
backend/main.py
Normal file
@@ -0,0 +1,55 @@
|
||||
# D:\GNPL-Private\TimeCraft\backend\main.py
|
||||
|
||||
import os
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from dotenv import load_dotenv # For loading environment variables
|
||||
|
||||
from app.api import endpoints # Import your API router
|
||||
|
||||
# Load environment variables from the .env file.
|
||||
# This should be called early in your application's lifecycle.
|
||||
load_dotenv()
|
||||
|
||||
# Initialize the FastAPI application instance
|
||||
# Add additional metadata for professional API documentation
|
||||
app = FastAPI(
|
||||
title="AI-Powered Schedule and Task Planning Backend",
|
||||
description="FastAPI backend for ingesting user tasks, using an LLM for intelligent scheduling, and returning structured schedules.",
|
||||
version="1.0.0",
|
||||
docs_url="/docs", # Enable interactive API documentation (Swagger UI)
|
||||
redoc_url="/redoc", # Enable ReDoc documentation
|
||||
openapi_url="/openapi.json" # Specify the OpenAPI schema URL
|
||||
)
|
||||
|
||||
# Configure CORS (Cross-Origin Resource Sharing) middleware.
|
||||
# This is crucial for allowing your React frontend (running on a different port/domain)
|
||||
# to make requests to your FastAPI backend.
|
||||
origins = [
|
||||
os.getenv("FRONTEND_URL", "http://localhost:3000"), # Get frontend URL from .env, default to React's development port
|
||||
# Add other origins if your frontend is deployed elsewhere or has multiple access points
|
||||
# e.g., "https://your-production-frontend.com",
|
||||
# "http://localhost:8080" # If testing with another local frontend setup
|
||||
]
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=origins, # List of allowed origins
|
||||
allow_credentials=True, # Allow cookies and authentication headers to be sent
|
||||
allow_methods=["*"], # Allow all HTTP methods (GET, POST, PUT, DELETE, etc.)
|
||||
allow_headers=["*"], # Allow all headers in the request
|
||||
)
|
||||
|
||||
# Include the API router defined in app.api.endpoints.
|
||||
# All routes defined in endpoints.py will be prefixed with "/api/v1".
|
||||
app.include_router(endpoints.router, prefix="/api/v1")
|
||||
|
||||
# Define a root endpoint for basic health check or welcome message
|
||||
@app.get("/", summary="Root Endpoint", description="Provides a welcome message for the API.")
|
||||
async def root():
|
||||
"""
|
||||
Root endpoint for the API.
|
||||
Returns a simple welcome message to indicate the API is running.
|
||||
"""
|
||||
return {"message": "Welcome to the AI-Powered Schedule and Task Planning API! Access docs at /docs"}
|
||||
|
||||
Reference in New Issue
Block a user