File tree Expand file tree Collapse file tree 2 files changed +13
-15
lines changed Expand file tree Collapse file tree 2 files changed +13
-15
lines changed Original file line number Diff line number Diff line change 3
3
FROM google/appengine-python27
4
4
5
5
RUN apt-get update && apt-get install -y fortunes
6
+ ADD requirements.txt /home/vmagent/app/
7
+ RUN pip install -r requirements.txt
6
8
7
9
ADD . /home/vmagent/app/
Original file line number Diff line number Diff line change 1
- import webapp2
1
+ from flask import Flask , helpers
2
2
import subprocess
3
3
4
- MESSAGES = '/tmp/messages.txt'
4
+ app = Flask ( __name__ )
5
5
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'
12
7
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
17
13
18
- app = webapp2 . WSGIApplication ([( '/' , HelloHandler ),
19
- ( '/ messages' , MessagesHandler )],
20
- debug = True )
14
+ @ app . route ( "/messages" )
15
+ def messages ():
16
+ return helpers . send_file ( MESSAGES )
You can’t perform that action at this time.
0 commit comments