Implement ProgCode identity and real shared reading UI kit
Build and deploy / deploy (push) Successful in 2m39s
Build and deploy / deploy (push) Successful in 2m39s
This commit is contained in:
1 parent
99c848189e
commit
12562baeb5
2040 files changed
+184656
-181
No files matched your search
@@ -0,0 +1,15 @@
|
||||
import argparse,http.server,functools,json,os
|
||||
from pathlib import Path
|
||||
p=argparse.ArgumentParser();p.add_argument('--root',type=Path,required=True);p.add_argument('--manifest',type=Path,required=True);p.add_argument('--allow-external',action='store_true');a=p.parse_args();m=json.loads(a.manifest.read_text())
|
||||
class Handler(http.server.SimpleHTTPRequestHandler):
|
||||
def end_headers(self):
|
||||
if not a.allow_external:self.send_header('Content-Security-Policy',"default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; font-src 'self'; frame-src 'self'; object-src 'none'")
|
||||
self.send_header('X-Review-Source',m['sourceHash']);self.send_header('X-Review-Build',m['buildHash']);self.send_header('Cache-Control','no-store');super().end_headers()
|
||||
def send_error(self,code,message=None,explain=None):
|
||||
if code==404:
|
||||
b=(a.root/'404.html').read_bytes();self.send_response(404);self.send_header('Content-Type','text/html; charset=utf-8');self.send_header('Content-Length',str(len(b)));self.end_headers()
|
||||
if self.command!='HEAD':self.wfile.write(b)
|
||||
else:super().send_error(code,message,explain)
|
||||
s=http.server.ThreadingHTTPServer(('127.0.0.1',0),functools.partial(Handler,directory=str(a.root)))
|
||||
local={'pid':os.getpid(),'port':s.server_port,'url':f'http://127.0.0.1:{s.server_port}','staticRoot':str(a.root),'sourceHash':m['sourceHash'],'buildHash':m['buildHash'],'analyticsIsolation':'none; explicitSDKharnessmustinterceptstats' if a.allow_external else 'viewerresponseCSPblocksexternals; productoutputbytesunchanged'}
|
||||
(a.manifest.parent/('sdk-service.json' if a.allow_external else 'local-service.json')).write_text(json.dumps(local,indent=2)+'\n');s.serve_forever()
|
||||
Reference in new issue
Block a user