Skip to content

Commit abee2e8

Browse files
committed
add requirements.txt and switch to flask
1 parent e4702e7 commit abee2e8

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
FROM google/appengine-python27
44

55
RUN apt-get update && apt-get install -y fortunes
6+
ADD requirements.txt /home/vmagent/app/
7+
RUN pip install -r requirements.txt
68

79
ADD . /home/vmagent/app/

main.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
import webapp2
1+
from flask import Flask, helpers
22
import subprocess
33

4-
MESSAGES = '/tmp/messages.txt'
4+
app = Flask(__name__)
55

6-
class HelloHandler(webapp2.RequestHandler):
7-
def get(self):
8-
msg = subprocess.check_output('/usr/games/fortune')
9-
with open(MESSAGES, 'a') as f: f.write(msg)
10-
self.response.headers['Content-Type'] = 'text/plain'
11-
self.response.out.write(msg)
6+
MESSAGES = '/tmp/messages.txt'
127

13-
class MessagesHandler(webapp2.RequestHandler):
14-
def get(self):
15-
with open(MESSAGES, 'r') as f:
16-
for msg in f: self.response.out.write(msg)
8+
@app.route("/")
9+
def fortune():
10+
msg = subprocess.check_output('/usr/games/fortune')
11+
with open(MESSAGES, 'a') as f: f.write(msg)
12+
return msg
1713

18-
app = webapp2.WSGIApplication([('/', HelloHandler),
19-
('/messages', MessagesHandler)],
20-
debug=True)
14+
@app.route("/messages")
15+
def messages():
16+
return helpers.send_file(MESSAGES)

0 commit comments

Comments
 (0)