# cPy - simple aio WebApp showing "Hello World"
# provided by Anthony Vogelaar, Perth Scotland
# rev 0.10  2025-02-27  initial release

import  os;         os.system('clear')
import  asyncio
from    microdot    import  Microdot
import  webbrowser

# =========================== local ================================

def openBrowser(port=5000):
    webbrowser.open('localhost:5000', new=1)             # open een new browser window

# ========================== webserver =============================

def webServer(port=5000):
    app = Microdot()

    @app.route('/')
    async def index(request):
        return 'Hello, world!'

    return app

# ============================ Main ================================

class Main:

    def __init__(self, port=5000):
        self.port = port
        openBrowser()
        asyncio.run(self.aioInit())


    async def aioInit(self):
        app    = webServer()
        asyncio.create_task(app.start_server(port=self.port))
        while True:
            print('*', end='', flush=True)
            await asyncio.sleep(1)


Main()

# ============================= end =================================
