This repository was archived by the owner on Apr 22, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
104 lines (85 loc) · 4.11 KB
/
Copy pathapp.py
File metadata and controls
104 lines (85 loc) · 4.11 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from contextlib import asynccontextmanager
from datetime import datetime
import pytz
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from starlette.responses import HTMLResponse
from src.database.connectors import mongo, async_mongo
from src.database.redis_service import initialize_redis, cleanup_redis
from utils.loggings import setup_custom_logger
from utils.typesense.typesense_utils import index_typesense
@asynccontextmanager
async def lifespan(app: FastAPI):
# Initialize MongoDB connections
mongo.connect() # Synchronous connection
await async_mongo.connect() # Asynchronous connection
# Initialize Redis
await initialize_redis()
# Initialization
await index_typesense()
yield
# Shutdown
mongo.close() # Close synchronous connection
await async_mongo.close() # Close asynchronous connection
# Cleanup Redis
await cleanup_redis()
app = FastAPI(lifespan=lifespan)
custom_logger = setup_custom_logger()
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Allow all origins
allow_credentials=True,
allow_methods=["*"], # Allow all methods (GET, POST, PUT, DELETE, etc.)
allow_headers=["*"], # Allow all headers
)
from src.routers import user_routers, admin_routers, store_routers, invite_routers, notification_routers, ticket_routers, audio_routers, item_routers, stock_routers, instant_sell_routers, transaction_routers, chat_bot_stream, landing_page_routers, health_routers, home_routers, customer_vendor_routers
app.include_router(stock_routers.router, prefix="/stocks", tags=["stocks"])
app.include_router(transaction_routers.router, prefix="/transactions", tags=["transactions"])
app.include_router(item_routers.router, prefix="/items", tags=["items"])
app.include_router(audio_routers.router, prefix="/audios", tags=["audio"])
app.include_router(invite_routers.router, prefix="/invites", tags=["invite"])
app.include_router(user_routers.router, prefix="/users", tags=["users"])
app.include_router(admin_routers.router, prefix="/admin", tags=["admin"])
app.include_router(store_routers.router, prefix="/stores", tags=["stores"])
app.include_router(ticket_routers.router, prefix="/tickets", tags=["tickets"])
app.include_router(notification_routers.router, prefix="/notifications", tags=["notifications"])
# app.include_router(import_export_routers.router, prefix="/import_export", tags=["import_export"])
app.include_router(instant_sell_routers.router, prefix="/instant_sell", tags=["instant_sell"])
app.include_router(chat_bot_stream.router, prefix="/chat_bot", tags=["chat_bot"])
app.include_router(landing_page_routers.router, prefix="/api/landing-page", tags=["landing_page"])
app.include_router(health_routers.router, prefix="/health", tags=["health"])
app.include_router(home_routers.router, prefix="/home", tags=["home"])
app.include_router(customer_vendor_routers.router, prefix="/customer_vendor", tags=["customer_vendor"])
@app.get("/", response_class=HTMLResponse)
async def read_root():
# Get the current UTC time
utc_now = datetime.utcnow()
# Convert the current UTC time to Indian Standard Time (IST)
ist_now = utc_now.replace(tzinfo=pytz.utc).astimezone(pytz.timezone("Asia/Kolkata"))
# Format the IST time
formatted_time = ist_now.strftime("%a %b %d %Y %H:%M:%S IST (Indian Standard Time)")
html_content = f"""
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
<div class="h-screen w-screen bg-black flex items-center justify-center">
<div style="width: 800px" class="text-gray-100 text-center">
<h1 class="text-5xl font-bold">System is Live! 🎉</h1>
<p class="mt-8">Current time</p>
<p class="mt-2">{formatted_time}</p>
</div>
</div>
</body>
</html>
"""
return HTMLResponse(content=html_content, status_code=200)
if __name__ == "__main__":
# Include routers
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8560)