kamau1 commited on
Commit
90b3106
·
verified ·
1 Parent(s): 4454b6a

Upload 10 files

Browse files
Files changed (1) hide show
  1. main.py +108 -9
main.py CHANGED
@@ -1,8 +1,11 @@
1
  import os
2
  import sys
3
  import logging
4
- from fastapi import FastAPI, HTTPException, Depends
5
  from fastapi.middleware.cors import CORSMiddleware
 
 
 
6
  import uvicorn
7
  from dotenv import load_dotenv
8
 
@@ -39,11 +42,55 @@ except ImportError:
39
  # Load environment variables
40
  load_dotenv()
41
 
42
- # Create FastAPI app
43
  app = FastAPI(
44
  title="Seamo Auth Server",
45
- description="Authentication and non-AI services for the Seamo platform",
46
- version="1.0.0"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  )
48
 
49
  # Configure CORS
@@ -390,15 +437,67 @@ async def shutdown_db_client():
390
  except Exception as e:
391
  logger.error(f"Error closing database connection: {str(e)}")
392
 
393
- # Root endpoint
394
- @app.get("/")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
395
  async def root():
396
- return {"message": "Welcome to Seamo Auth Server"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
397
 
398
  # Health check endpoint
399
- @app.get("/health")
400
  async def health_check():
401
- return {"status": "healthy"}
 
 
 
 
 
 
 
 
 
 
 
402
 
403
  # Import and include routers
404
  from app.api.routes import auth_router, projects_router, journals_router
 
1
  import os
2
  import sys
3
  import logging
4
+ from fastapi import FastAPI, HTTPException, Depends, Request
5
  from fastapi.middleware.cors import CORSMiddleware
6
+ from fastapi.openapi.docs import get_swagger_ui_html, get_redoc_html
7
+ from fastapi.openapi.utils import get_openapi
8
+ from fastapi.staticfiles import StaticFiles
9
  import uvicorn
10
  from dotenv import load_dotenv
11
 
 
42
  # Load environment variables
43
  load_dotenv()
44
 
45
+ # Create FastAPI app with detailed metadata
46
  app = FastAPI(
47
  title="Seamo Auth Server",
48
+ description="""
49
+ # Seamo Authentication API
50
+
51
+ The Seamo Auth Server provides authentication and user management services for the Seamo platform.
52
+
53
+ ## Features
54
+
55
+ * User registration and authentication
56
+ * Project management
57
+ * Journal management
58
+ * Access control
59
+
60
+ ## Authentication
61
+
62
+ Most endpoints require authentication. Use the /api/auth/token endpoint to obtain access tokens.
63
+ """,
64
+ version="1.0.0",
65
+ contact={
66
+ "name": "Seamo Team",
67
+ "url": "https://seamo.earth/contact",
68
+ "email": "[email protected]",
69
+ },
70
+ license_info={
71
+ "name": "MIT",
72
+ "url": "https://opensource.org/licenses/MIT",
73
+ },
74
+ openapi_tags=[
75
+ {
76
+ "name": "Authentication",
77
+ "description": "Operations related to user authentication and token management",
78
+ },
79
+ {
80
+ "name": "Projects",
81
+ "description": "Operations related to project management",
82
+ },
83
+ {
84
+ "name": "Journals",
85
+ "description": "Operations related to journal management",
86
+ },
87
+ {
88
+ "name": "General",
89
+ "description": "General server information and health checks",
90
+ },
91
+ ],
92
+ docs_url=None, # Disable default docs
93
+ redoc_url=None # Disable default redoc
94
  )
95
 
96
  # Configure CORS
 
437
  except Exception as e:
438
  logger.error(f"Error closing database connection: {str(e)}")
439
 
440
+ # Custom API documentation routes
441
+ @app.get("/docs", include_in_schema=False)
442
+ async def custom_swagger_ui_html():
443
+ return get_swagger_ui_html(
444
+ openapi_url=app.openapi_url,
445
+ title=f"{app.title} - Swagger UI",
446
+ oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url,
447
+ swagger_js_url="https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui-bundle.js",
448
+ swagger_css_url="https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui.css",
449
+ swagger_favicon_url="https://fastapi.tiangolo.com/img/favicon.png",
450
+ )
451
+
452
+ @app.get("/redoc", include_in_schema=False)
453
+ async def redoc_html():
454
+ return get_redoc_html(
455
+ openapi_url=app.openapi_url,
456
+ title=f"{app.title} - ReDoc",
457
+ redoc_js_url="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js",
458
+ redoc_favicon_url="https://fastapi.tiangolo.com/img/favicon.png",
459
+ )
460
+
461
+ # Root endpoint with API information
462
+ @app.get("/", tags=["General"])
463
  async def root():
464
+ """
465
+ Root endpoint providing information about the Seamo Auth Server API.
466
+
467
+ Returns:
468
+ dict: Basic information about the API and links to documentation.
469
+ """
470
+ return {
471
+ "message": "Welcome to Seamo Auth Server API",
472
+ "version": "1.0.0",
473
+ "documentation": {
474
+ "swagger_ui": "/docs",
475
+ "redoc": "/redoc",
476
+ "openapi_json": "/openapi.json"
477
+ },
478
+ "endpoints": {
479
+ "health": "/health",
480
+ "auth": "/api/auth",
481
+ "projects": "/api/projects",
482
+ "journals": "/api/journals"
483
+ }
484
+ }
485
 
486
  # Health check endpoint
487
+ @app.get("/health", tags=["General"])
488
  async def health_check():
489
+ """
490
+ Health check endpoint to verify the server is running properly.
491
+
492
+ Returns:
493
+ dict: Status information about the server.
494
+ """
495
+ return {
496
+ "status": "healthy",
497
+ "version": "1.0.0",
498
+ "database_connected": hasattr(app, "db_conn"),
499
+ "database_type": getattr(app, "db_type", "unknown")
500
+ }
501
 
502
  # Import and include routers
503
  from app.api.routes import auth_router, projects_router, journals_router