A trivial guestbook app

Functions for GET and POST endpoints. A redis.yaml to deploy redis on
kubernetes.  And a deploy.sh to deploy the fission functions with
routes.
This commit is contained in:
Soam Vasani
2017-01-18 15:30:51 -08:00
parent 9ffba72c11
commit 928d96c080
4 changed files with 104 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
#
# Handles GET /guestbook -- returns a list of items in the guestbook
# with a form to add more.
#
from flask import current_app, escape
import redis
# Connect to redis. This is run only when this file is loaded; as
# long as the pod is alive, the connection is reused.
redisConnection = redis.StrictRedis(host='redis.guestbook', port=6379, db=0)
def main():
messages = redisConnection.lrange('guestbook', 0, -1)
items = [("<li>%s</li>" % escape(m.decode('utf-8'))) for m in messages]
ul = "<ul>%s</ul>" % "\n".join(items)
return """
<html><body>
<h1>Guestbook</h1>
<form action="/guestbook" method="POST">
<input type="text" name="text">
<button type="submit">Add</button>
</form>
<hr/>
%s
</body></html>
""" % ul