add: fastapi wrapped baru mau di tes di Gajah Mada
This commit is contained in:
41
api-app/run.py
Normal file
41
api-app/run.py
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Script to run the FastAPI server for DICOM migration service.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import uvicorn
|
||||
import argparse
|
||||
|
||||
def parse_args():
|
||||
"""Parse command-line arguments."""
|
||||
parser = argparse.ArgumentParser(description='DICOM Migration API Server')
|
||||
parser.add_argument('--host', default='0.0.0.0', help='Host to bind to')
|
||||
parser.add_argument('--port', type=int, default=8000, help='Port to bind to')
|
||||
parser.add_argument('--token', help='API token for authentication (overrides environment variable)')
|
||||
parser.add_argument('--reload', action='store_true', help='Enable auto-reload for development')
|
||||
return parser.parse_args()
|
||||
|
||||
def main():
|
||||
"""Main function to run the API server."""
|
||||
args = parse_args()
|
||||
|
||||
# Set API token if provided
|
||||
if args.token:
|
||||
os.environ['API_TOKEN'] = args.token
|
||||
|
||||
# Check if API_TOKEN is set
|
||||
if not os.environ.get('API_TOKEN'):
|
||||
print("WARNING: API_TOKEN not set. Using default token 'token-his2-untuk-hit-api-migrasi-clarity'.")
|
||||
print("Set environment variable API_TOKEN or use --token argument for better security.")
|
||||
|
||||
print(f"Starting DICOM Migration API server on {args.host}:{args.port}")
|
||||
uvicorn.run(
|
||||
"main:app",
|
||||
host=args.host,
|
||||
port=args.port,
|
||||
reload=args.reload
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user