MkDocs documentation integration
This commit is contained in:
133
main.py
133
main.py
@@ -2,6 +2,7 @@ import logging
|
||||
from datetime import datetime
|
||||
|
||||
from fastapi import Depends, FastAPI, HTTPException
|
||||
from fastapi.responses import HTMLResponse, RedirectResponse
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -36,28 +37,10 @@ app.include_router(api_router, prefix="/api/v1")
|
||||
|
||||
# Public Routes (no authentication required)
|
||||
# Core application endpoints (Public Routes, no authentication required)
|
||||
@app.get("/")
|
||||
def root():
|
||||
return {
|
||||
"message": f"{settings.project_name} v{settings.version}",
|
||||
"status": "operational",
|
||||
"docs": "/docs",
|
||||
"features": [
|
||||
"JWT Authentication",
|
||||
"Marketplace-aware product import",
|
||||
"Multi-shop product management",
|
||||
"Stock management with location tracking",
|
||||
],
|
||||
"supported_marketplaces": [
|
||||
"Letzshop",
|
||||
"Amazon",
|
||||
"eBay",
|
||||
"Etsy",
|
||||
"Shopify",
|
||||
"Other",
|
||||
],
|
||||
"auth_required": "Most endpoints require Bearer token authentication",
|
||||
}
|
||||
@app.get("/", include_in_schema=False)
|
||||
async def root():
|
||||
"""Redirect root to documentation"""
|
||||
return RedirectResponse(url="/documentation")
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
@@ -66,7 +49,25 @@ def health_check(db: Session = Depends(get_db)):
|
||||
try:
|
||||
# Test database connection
|
||||
db.execute(text("SELECT 1"))
|
||||
return {"status": "healthy", "timestamp": datetime.utcnow()}
|
||||
return {"status": "healthy",
|
||||
"timestamp": datetime.utcnow(),
|
||||
"message": f"{settings.project_name} v{settings.version}",
|
||||
"docs": {
|
||||
"swagger": "/docs",
|
||||
"redoc": "/redoc",
|
||||
"openapi": "/openapi.json",
|
||||
"complete": "Documentation site URL here"
|
||||
},
|
||||
"features": [
|
||||
"JWT Authentication",
|
||||
"Marketplace-aware product import",
|
||||
"Multi-shop product management",
|
||||
"Stock management with location tracking",
|
||||
],
|
||||
"supported_marketplaces": [
|
||||
"Letzshop",
|
||||
],
|
||||
"auth_required": "Most endpoints require Bearer token authentication", }
|
||||
except Exception as e:
|
||||
logger.error(f"Health check failed: {e}")
|
||||
raise HTTPException(status_code=503, detail="Service unhealthy")
|
||||
@@ -74,6 +75,92 @@ def health_check(db: Session = Depends(get_db)):
|
||||
# Add this temporary endpoint to your router:
|
||||
|
||||
|
||||
# Documentation redirect endpoints
|
||||
@app.get("/documentation", response_class=HTMLResponse, include_in_schema=False)
|
||||
async def documentation_page():
|
||||
"""Enhanced documentation hub page"""
|
||||
return """
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Letzshop Import - Documentation</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 40px auto;
|
||||
padding: 20px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.header { text-align: center; margin-bottom: 40px; }
|
||||
.logo { font-size: 2em; margin-bottom: 10px; }
|
||||
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; margin: 30px 0; }
|
||||
.card {
|
||||
border: 1px solid #e1e5e9;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
transition: box-shadow 0.2s;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
.card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
|
||||
.card h3 { margin-top: 0; color: #1976d2; }
|
||||
.badge {
|
||||
display: inline-block;
|
||||
background: #1976d2;
|
||||
color: white;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 0.8em;
|
||||
margin-left: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<div class="logo">📚 Letzshop Import Documentation</div>
|
||||
<p>Choose your documentation experience</p>
|
||||
</div>
|
||||
|
||||
<div class="cards">
|
||||
<a href="/docs" class="card">
|
||||
<h3>🔧 Interactive API Docs <span class="badge">LIVE</span></h3>
|
||||
<p>Swagger UI interface for testing API endpoints directly in your browser. Perfect for development and API exploration.</p>
|
||||
</a>
|
||||
|
||||
<a href="/redoc" class="card">
|
||||
<h3>📖 API Reference</h3>
|
||||
<p>Clean, readable API documentation with ReDoc. Great for understanding API structure and parameters.</p>
|
||||
</a>
|
||||
|
||||
<a href="#" class="card">
|
||||
<h3>📚 Complete Documentation</h3>
|
||||
<p>Comprehensive project documentation with guides, tutorials, architecture, and development info.</p>
|
||||
</a>
|
||||
|
||||
<a href="#" class="card">
|
||||
<h3>🚀 Getting Started</h3>
|
||||
<p>Step-by-step installation and setup guide to get you up and running quickly.</p>
|
||||
</a>
|
||||
|
||||
<a href="#" class="card">
|
||||
<h3>🧪 Testing Guide</h3>
|
||||
<p>Testing conventions, how to run tests, and contribute to the test suite.</p>
|
||||
</a>
|
||||
|
||||
<a href="/health" class="card">
|
||||
<h3>💚 System Health</h3>
|
||||
<p>Check the current status and health of the API and its dependencies.</p>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div style="text-align: center; margin-top: 40px; color: #666;">
|
||||
<p>Need help? Check our <a href="https://github.com/yourusername/letzshop-import/issues">GitHub Issues</a></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
|
||||
Reference in New Issue
Block a user