Async example of static file serving
This commit is contained in:
19
examples/static/static_async.py
Normal file
19
examples/static/static_async.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from microdot_asyncio import Microdot
|
||||
from microdot import send_file
|
||||
app = Microdot()
|
||||
|
||||
|
||||
@app.route('/')
|
||||
async def index(request):
|
||||
return send_file('static/index.html')
|
||||
|
||||
|
||||
@app.route('/static/<path:path>')
|
||||
async def static(request, path):
|
||||
if '..' in path:
|
||||
# directory traversal is not allowed
|
||||
return 'Not found', 404
|
||||
return send_file('static/' + path)
|
||||
|
||||
|
||||
app.run(debug=True)
|
||||
Reference in New Issue
Block a user