from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from routes import router
from database import engine
import models

app = FastAPI()

# Luodaan tietokantataulut
models.Base.metadata.create_all(bind=engine)

# Lisätään CORS-tuki
app.add_middleware(
    CORSMiddleware,
    allow_origins=[
        "http://localhost:5500",  # Frontend development server
        "http://192.168.100.4",   # Production server
        "http://192.168.100.4:80",  # Production server with explicit port
        "http://localhost:8000",   # Backend development server
    ],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

app.include_router(router)

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)
