In [1]:
import growler
In [2]:
growler.__meta__.version_info
Out[2]:
Create growler application with name NotebookServer
In [3]:
app = growler.App("NotebookServer")
Add a general purpose method which prints ip address and the USER-AGENT header
In [4]:
@app.use
def print_client_info(req, res):
ip = req.ip
reqpath = req.path
print("[{ip}] {path}".format(ip=ip, path=reqpath))
print(" >", req.headers['USER-AGENT'])
print(flush=True)
Next, add a route matching any GET requests for the root (/) of the site. This uses a simple global variable to count the number times this page has been accessed, and return text to the client
In [5]:
i = 0
@app.get("/")
def index(req, res):
global i
res.send_text("It Works! (%d)" % i)
i += 1
We can see the tree of middleware all requests will pass through - Notice the router object that was implicitly created which will match all requests.
In [6]:
app.print_middleware_tree()
Use the helper method to create the asyncio server listening on port 9000.
In [7]:
app.create_server_and_run_forever(host='127.0.0.1', port=9000)
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: