playwright-cli/examples/serve_fixture.py
Version b85c7a736bb4.bb1 · Apache-2.0. This preview displays packaged text and does not execute code. Treat the contents as untrusted instructions.
← Return to resource and package checksum
"""Serve this synthetic fixture on loopback only. Apache-2.0, BB Skills 2026."""
import http.server
import pathlib
from urllib.parse import urlsplit
root = pathlib.Path(__file__).parent
class Handler(http.server.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory=str(root), **kwargs)
def do_GET(self):
if urlsplit(self.path).path == '/api/ideas':
data = b'{"ideas":["local default"]}'
self.send_response(200)
self.send_header('Content-Type','application/json')
self.send_header('Content-Length',str(len(data)))
self.end_headers()
self.wfile.write(data)
return
super().do_GET()
def log_message(self, fmt, *args):
pass
server = http.server.ThreadingHTTPServer(('127.0.0.1',8767), Handler)
print('Synthetic fixture serving at http://127.0.0.1:8767/index.html',flush=True)
server.serve_forever()