Utility to send a JSON response with CORS headers.
(self, data, status_code=200)
| 732 | self.send_json_response({"error": f"Could not list models: {e}"}, status_code=500) |
| 733 | |
| 734 | def send_json_response(self, data, status_code=200): |
| 735 | """Utility to send a JSON response with CORS headers.""" |
| 736 | self.send_response(status_code) |
| 737 | self.send_header('Content-Type', 'application/json') |
| 738 | self.send_header('Access-Control-Allow-Origin', '*') |
| 739 | self.end_headers() |
| 740 | response = json.dumps(data, indent=2) |
| 741 | self.wfile.write(response.encode('utf-8')) |
| 742 | |
| 743 | def start_server(port=8001): |
| 744 | """Starts the API server.""" |
no test coverage detected