I have trouble to find a wildcard url matching pattern which matches all incoming urls. This just matches a url which has nothing more than the hostname:
import asyncio
from aiohttp import web
@asyncio.coroutine
def handle(request):
print('there was a request')
text = "Hello "
return web.Response(body=text.encode('utf-8'))
@asyncio.coroutine
def init(loop):
app = web.Application(loop=loop)
app.router.add_route('GET', '/', handle)
srv = yield from loop.create_server(app.make_handler(),
'127.0.0.1', 9999)
print("Server started at http://'127.0.0.1:9999'")
return srv
loop = asyncio.get_event_loop()
loop.run_until_complete(init(loop))
try:
loop.run_forever()
except KeyboardInterrupt:
pass
So it should call the handler anytime there is a request regardless of the path. If its http://127.0.0.1:9999/ or http://127.0.0.1:9999/test/this/test/
I looked it up here http://aiohttp.readthedocs.org/en/stable/web.html#aiohttp-web-variable-handler with no success for the right clue
You can use app.router.add_route('GET', '/{tail:.*}', handle)
for catching all urls.
The part after the colon (:
) is a regular expression. .*
regexp describes everything, including path separators (/
) and other symbols.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With