File size: 1,649 Bytes
0646b18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
from fastapi import FastAPI
from contextlib import asynccontextmanager
import uvicorn
import argparse

from crm_api.database import init_db
from crm_api.accounts import router as accounts_router
from crm_api.leads import router as leads_router
from crm_api.contacts import router as contacts_router
from crm_api.opportunities import router as opportunities_router
import os


@asynccontextmanager
async def lifespan(app: FastAPI):
    # Startup
    init_db()
    yield
    # Shutdown (if needed)


app = FastAPI(title="CRM System API", version="1.0.0", lifespan=lifespan)

# Include routers for different API categories
app.include_router(accounts_router)
app.include_router(leads_router)
app.include_router(contacts_router)
app.include_router(opportunities_router)


def main():
    """Main entry point for running the CRM API server"""
    parser = argparse.ArgumentParser(description="CRM System API Server")
    parser.add_argument("--host", default="0.0.0.0", help="Host to bind to")

    # Get port from env var with fallback to default
    env_port = os.environ.get("DYNACONF_SERVER_PORTS__CRM_API", "8007")
    print(f"[CRM Server] Reading DYNACONF_SERVER_PORTS__CRM_API from environment: {env_port}")

    parser.add_argument(
        "--port",
        type=int,
        default=int(env_port),
        help="Port to bind to",
    )
    parser.add_argument("--reload", action="store_true", help="Enable auto-reload")

    args = parser.parse_args()

    print(f"[CRM Server] Starting CRM API server on {args.host}:{args.port}")
    uvicorn.run(app, host=args.host, port=args.port, reload=args.reload)


if __name__ == "__main__":
    main()