[docs]classServer:"""Base TCP server"""host:str="localhost"port:int=8012cors:str="*""Enable CORS"cert:str=None"the path to the SSL certificate"key:str=None"the path to the SSL key"ca_cert:str=None"the trusted root CA certificates"WEBSOCKET_MAX_SIZE=2**28REQUEST_MAX_SIZE=2**28
[docs]defrun(self):"""Simple Runner When using gunicorn, this gets replace by the gunicorn runner. gunicorn is responsible for handling the ssl certification, and the port binding. ```shell $ gunicorn --certfile=server.crt --keyfile=server.key --bind 0.0.0.0:443 test:app ``` """asyncdefinit_server():runner=web.AppRunner(self.app)awaitrunner.setup()ifnotself.cert:site=web.TCPSite(runner,self.host,self.port)returnawaitsite.start()ssl_context=ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)ssl_context.load_cert_chain(certfile=self.cert,keyfile=self.key)ifself.ca_cert:ssl_context.load_verify_locations(self.ca_cert)ssl_context.verify_mode=ssl.CERT_REQUIREDelse:ssl_context.verify_mode=ssl.CERT_OPTIONALsite=web.TCPSite(runner,self.host,self.port,ssl_context=ssl_context)returnawaitsite.start()event_loop=asyncio.get_event_loop()event_loop.run_until_complete(init_server())event_loop.run_forever()