# *Py - aio microdot webserver serving static files
# Copyright by Anthony Vogelaar, Perth Scotland
# rev 0.10  2025-11-26  initial release

import	asyncio
from	microdot	import	Microdot, send_file

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

app = Microdot()

@app.route('/')
async def index(request):
    return send_file('static/index_2.html')


@app.route('static/<path:path>')
async def static(request, path):
    if '..' in path:
        return 'Not found', 404		# directory traversal not allowed
    return send_file(f'static/{path}')

# ======================= main ==========================

# Three cooperative asyncio tasks
#    task #1: webserver
#    task #2: print '*' @ 1 Hz
async def main():
    asyncio.create_task(app.start_server(debug=True))	# task #1
    while True:											# task #2
        await asyncio.sleep(1)
        print('*', end='')


asyncio.run(main())
    
# ======================== end ===========================
