| 123456789101112131415161718192021222324252627282930313233343536373839 |
- """Serve isolated browser regression checks without the API, model or user data.
- Run `python scripts/check_frontend.py`, then open http://127.0.0.1:8081.
- Only a temporary copy of frontend assets is exposed. Ctrl+C stops the server.
- """
- from functools import partial
- from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
- from pathlib import Path
- from tempfile import TemporaryDirectory
- import json
- import shutil
- ROOT = Path(__file__).resolve().parents[1]
- class Handler(SimpleHTTPRequestHandler):
- def do_GET(self):
- if self.path.startswith('/api/'):
- body = json.dumps({'model': 'test', 'items': []}).encode()
- self.send_response(200)
- self.send_header('Content-Type', 'application/json')
- self.end_headers()
- self.wfile.write(body)
- else:
- super().do_GET()
- if __name__ == '__main__':
- with TemporaryDirectory(prefix='deep-agent-frontend-') as directory:
- shutil.copytree(ROOT / 'static', Path(directory) / 'static')
- shutil.copyfile(ROOT / 'tests/frontend_markdown.html', Path(directory) / 'index.html')
- server = ThreadingHTTPServer(('127.0.0.1', 8081), partial(Handler, directory=directory))
- print('Frontend checks: http://127.0.0.1:8081', flush=True)
- try:
- server.serve_forever()
- except KeyboardInterrupt:
- pass
- finally:
- server.server_close()
|