# Define an app class MyApp(flx.Widget): def init(self): with flx.HBox(): CodeEditor(flex=1) flx.Widget(flex=1) # Dump it to a dictionary of assets that we can serve. Make the main # page index.html. The link=0 means to pack the whole app into a single # html page (note that data (e.g. images) will still be separate). app = flx.App(MyApp) assets = app.dump('index.html', link=0) # Do the Asgineer thing. Use make_asset_handler() for a solid and # lightning fast way to serve assets from memory (it includes HTTP # caching and compression). asset_handler = asgineer.utils.make_asset_handler(assets) @asgineer.to_asgi async def main_handler(request): return await asset_handler(request) if __name__ == '__main__': asgineer.run(main_handler, "uvicorn", "localhost:8080")
""" import os import asgineer try: from stats import StatsCollector, UdpStatsReceiver from stats import stats_handler except ImportError: from mypaas.stats import StatsCollector, UdpStatsReceiver from mypaas.stats import stats_handler # Create a stats collector db_dir = os.path.expanduser("~/_stats") collector = StatsCollector(db_dir) # Start a thread that receives stats via udp and puts it into the collector udp_stats_receiver = UdpStatsReceiver(collector) udp_stats_receiver.start() @asgineer.to_asgi async def main_handler(request): return await stats_handler(request, collector) if __name__ == "__main__": asgineer.run(main_handler, "uvicorn", "0.0.0.0:80", log_level="warning")
""" Entrypoint for the MyPaas daemon. """ import asgineer from mypaas.daemon import main_handler, SystemStatsProducer @asgineer.to_asgi async def main(request): return await main_handler(request) stats_producer = SystemStatsProducer() stats_producer.start() if __name__ == "__main__": # Host on localhost. Traefik will accept https connections and route via # localhost:88. Don't allow direct acces, or we have insecure connection. asgineer.run(main, "uvicorn", "localhost:88", log_level="warning")