Skip to content

Commit

Permalink
add_route/add_handler
Browse files Browse the repository at this point in the history
  • Loading branch information
manatlan committed Nov 12, 2023
1 parent 668e7c1 commit 1fa86aa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions htag/runners/chromeapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ def __init__(self,tagClass:type):
self.hrenderer = None
self.tagClass = tagClass

self._routes=[]


def instanciate(self,url:str):
init = commons.url2ak(url)
Expand Down Expand Up @@ -240,7 +242,13 @@ async def on_disconnect(this, websocket, close_code):
WebSocketRoute("/ws", WsInteract),
])

for path,handler in self._routes:
asgi.add_route( path,handler )

self._server = threading.Thread(name='ChromeAppServer', target=uvicorn.run,args=(asgi,),kwargs=dict(host=host, port=port, log_level="critical"))
self._server.start()
self._chromeapp.wait( self._server )
os._exit(0) # to force quit the thread/uvicorn server

def add_route(self, path:str, handler):
self._routes.append( (path,handler) )
10 changes: 9 additions & 1 deletion htag/runners/winapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def __init__(self,tagClass:type):
self.tagClass = tagClass
self.hrenderer = None

self._routes=[]

try: # https://bugs.python.org/issue37373 FIX: tornado/py3.8 on windows
if sys.platform == 'win32':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
Expand Down Expand Up @@ -109,6 +111,12 @@ def wait(self,thread):
def exit(self):
pass
self.chromeapp = FakeChromeApp()
app = tornado.web.Application([(r"/", MainHandler),(r"/ws", SocketHandler)])
handlers=[(r"/", MainHandler),(r"/ws", SocketHandler)]
for path,handler in self._routes:
handlers.append( ( path,handler ) )
app = tornado.web.Application(handlers)
app.listen(port)
tornado.ioloop.IOLoop.current().start()

def add_handler(self, path:str, handler:tornado.web.RequestHandler):
self._routes.append( (path,handler) )

0 comments on commit 1fa86aa

Please sign in to comment.