Files
the-nexus/l402_server.py
Alexander Whitestone 4c08119c9e
Some checks failed
Deploy Nexus / deploy (push) Failing after 4s
Staging Verification Gate / verify-staging (push) Failing after 4s
fix: port 8080 conflict between L402 server and preview (#1415) (#1431)
Merge PR #1431
2026-04-14 22:11:56 +00:00

39 lines
1.3 KiB
Python

#!/usr/bin/env python3
from http.server import HTTPServer, BaseHTTPRequestHandler
import json
import secrets
import os
class L402Handler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/api/cost-estimate':
# Simulate L402 Challenge
macaroon = secrets.token_hex(16)
invoice = "lnbc1..." # Mock invoice
self.send_response(402)
self.send_header('WWW-Authenticate', f'L402 macaroon="{macaroon}", invoice="{invoice}"')
self.send_header('Content-type', 'application/json')
self.end_headers()
response = {
"error": "Payment Required",
"message": "Please pay the invoice to access cost estimation."
}
self.wfile.write(json.dumps(response).encode())
else:
self.send_response(404)
self.end_headers()
def run(server_class=HTTPServer, handler_class=L402Handler, port=None):
if port is None:
port = int(os.environ.get('L402_PORT', 8080))
server_address = ('', port)
httpd = server_class(server_address, handler_class)
print(f"Starting L402 Skeleton Server on port {port}...")
httpd.serve_forever()
if __name__ == "__main__":
run()