Add authenticated documentation server
- Created docs_server.py with HTTP basic authentication - Added start-docs-server.sh for easy startup - Updated README.md with documentation access instructions - Provides working authentication when .htaccess isn't supported Usage: ./start-docs-server.sh [port] Credentials: langmem / langmem2025 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
39
README.md
39
README.md
@@ -18,6 +18,7 @@ LangMem uses a hybrid approach combining:
|
|||||||
- 📊 **Rich Metadata**: Flexible memory attributes
|
- 📊 **Rich Metadata**: Flexible memory attributes
|
||||||
- 🔒 **Secure API**: Bearer token authentication
|
- 🔒 **Secure API**: Bearer token authentication
|
||||||
- 🐳 **Docker Ready**: Containerized deployment
|
- 🐳 **Docker Ready**: Containerized deployment
|
||||||
|
- 📚 **Protected Documentation**: Basic auth-protected docs
|
||||||
- 🧪 **Comprehensive Tests**: Unit and integration tests
|
- 🧪 **Comprehensive Tests**: Unit and integration tests
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
@@ -278,6 +279,44 @@ For production deployment:
|
|||||||
4. Set up monitoring and logging
|
4. Set up monitoring and logging
|
||||||
5. Configure backup procedures
|
5. Configure backup procedures
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
The LangMem project includes comprehensive documentation with authentication protection.
|
||||||
|
|
||||||
|
### Accessing Documentation
|
||||||
|
|
||||||
|
Start the authenticated documentation server:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Start documentation server on port 8080 (default)
|
||||||
|
./start-docs-server.sh
|
||||||
|
|
||||||
|
# Or specify a custom port
|
||||||
|
./start-docs-server.sh 8090
|
||||||
|
```
|
||||||
|
|
||||||
|
**Access Credentials:**
|
||||||
|
- **Username:** `langmem`
|
||||||
|
- **Password:** `langmem2025`
|
||||||
|
|
||||||
|
**Available Documentation:**
|
||||||
|
- 📖 **Main Docs**: System overview and features
|
||||||
|
- 🏗️ **Architecture**: Detailed system architecture
|
||||||
|
- 📡 **API Reference**: Complete API documentation
|
||||||
|
- 🛠️ **Implementation**: Step-by-step setup guide
|
||||||
|
|
||||||
|
### Direct Server Usage
|
||||||
|
|
||||||
|
You can also run the documentation server directly:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 docs_server.py [port]
|
||||||
|
```
|
||||||
|
|
||||||
|
Then visit: `http://localhost:8080` (or your specified port)
|
||||||
|
|
||||||
|
Your browser will prompt for authentication credentials.
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
1. Fork the repository
|
1. Fork the repository
|
||||||
|
|||||||
105
docs_server.py
Executable file
105
docs_server.py
Executable file
@@ -0,0 +1,105 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Simple authenticated web server for LangMem documentation
|
||||||
|
"""
|
||||||
|
|
||||||
|
import http.server
|
||||||
|
import socketserver
|
||||||
|
import base64
|
||||||
|
import os
|
||||||
|
from urllib.parse import parse_qs
|
||||||
|
|
||||||
|
# Authentication credentials
|
||||||
|
USERNAME = "langmem"
|
||||||
|
PASSWORD = "langmem2025"
|
||||||
|
|
||||||
|
class AuthHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
|
||||||
|
"""HTTP handler with basic authentication"""
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, directory="docs", **kwargs)
|
||||||
|
|
||||||
|
def do_GET(self):
|
||||||
|
"""Handle GET requests with authentication"""
|
||||||
|
if self.authenticate():
|
||||||
|
super().do_GET()
|
||||||
|
else:
|
||||||
|
self.send_auth_request()
|
||||||
|
|
||||||
|
def authenticate(self):
|
||||||
|
"""Check if request has valid authentication"""
|
||||||
|
auth_header = self.headers.get('Authorization')
|
||||||
|
|
||||||
|
if not auth_header:
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
auth_type, credentials = auth_header.split(' ', 1)
|
||||||
|
if auth_type.lower() != 'basic':
|
||||||
|
return False
|
||||||
|
|
||||||
|
decoded = base64.b64decode(credentials).decode('utf-8')
|
||||||
|
username, password = decoded.split(':', 1)
|
||||||
|
|
||||||
|
return username == USERNAME and password == PASSWORD
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def send_auth_request(self):
|
||||||
|
"""Send authentication request to client"""
|
||||||
|
self.send_response(401)
|
||||||
|
self.send_header('WWW-Authenticate', 'Basic realm="LangMem Documentation"')
|
||||||
|
self.send_header('Content-type', 'text/html')
|
||||||
|
self.end_headers()
|
||||||
|
|
||||||
|
html = """
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Authentication Required</title>
|
||||||
|
<style>
|
||||||
|
body { font-family: Arial, sans-serif; text-align: center; margin-top: 100px; }
|
||||||
|
.container { max-width: 400px; margin: 0 auto; padding: 20px; border: 1px solid #ccc; border-radius: 10px; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h2>🔐 LangMem Documentation</h2>
|
||||||
|
<p>Authentication required to access documentation.</p>
|
||||||
|
<p><strong>Username:</strong> langmem<br>
|
||||||
|
<strong>Password:</strong> langmem2025</p>
|
||||||
|
<p>Please refresh the page and enter your credentials when prompted.</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"""
|
||||||
|
self.wfile.write(html.encode())
|
||||||
|
|
||||||
|
def start_server(port=8080):
|
||||||
|
"""Start the authenticated documentation server"""
|
||||||
|
try:
|
||||||
|
with socketserver.TCPServer(("", port), AuthHTTPRequestHandler) as httpd:
|
||||||
|
print(f"🌐 LangMem Documentation Server started!")
|
||||||
|
print(f"📍 URL: http://localhost:{port}")
|
||||||
|
print(f"🔑 Username: {USERNAME}")
|
||||||
|
print(f"🔑 Password: {PASSWORD}")
|
||||||
|
print(f"🛑 Press Ctrl+C to stop the server")
|
||||||
|
print("=" * 50)
|
||||||
|
httpd.serve_forever()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("\n🛑 Server stopped by user")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ Error starting server: {e}")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import sys
|
||||||
|
|
||||||
|
port = 8080
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
try:
|
||||||
|
port = int(sys.argv[1])
|
||||||
|
except ValueError:
|
||||||
|
print("Invalid port number. Using default port 8080.")
|
||||||
|
|
||||||
|
start_server(port)
|
||||||
12
start-docs-server.sh
Executable file
12
start-docs-server.sh
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Start LangMem Documentation Server with Authentication
|
||||||
|
|
||||||
|
echo "🚀 Starting LangMem Documentation Server..."
|
||||||
|
echo "🔐 Authentication enabled with basic auth"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Default port
|
||||||
|
PORT=${1:-8080}
|
||||||
|
|
||||||
|
# Start the authenticated server
|
||||||
|
python3 docs_server.py $PORT
|
||||||
Reference in New Issue
Block a user