Skip to content

Commit

Permalink
Switch to Flask to enable live updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhay Saxena committed Apr 3, 2019
1 parent 5a657c6 commit 788da79
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM python:3-alpine
WORKDIR /usr/src/app
EXPOSE 8000
COPY requirements.txt .
RUN pip install -qr requirements.txt
COPY server.py .
CMD ["python3", "./server.py"]
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Click==7.0
Flask==1.0.2
itsdangerous==1.1.0
Jinja2==2.10
MarkupSafe==1.1.1
Werkzeug==0.15.2
25 changes: 9 additions & 16 deletions server.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
from http.server import HTTPStatus, BaseHTTPRequestHandler
from socketserver import TCPServer
from flask import Flask

PORT = 8000
MESSAGE = "Hello, world!\n".encode("ascii")
MESSAGE = "Hello, world!\n"

app = Flask(__name__)

class Handler(BaseHTTPRequestHandler):
"""Respond to requests with hello."""

def do_GET(self):
"""Handle GET"""
self.send_response(HTTPStatus.OK)
self.send_header("Content-type", "text/plain")
self.send_header("Content-length", len(MESSAGE))
self.end_headers()
self.wfile.write(MESSAGE)
@app.route("/")
def root():
result = MESSAGE.encode("utf-8")
return result


print("Serving at port", PORT)
TCPServer.allow_reuse_address = True
httpd = TCPServer(("", PORT), Handler)
httpd.serve_forever()
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=PORT)

0 comments on commit 788da79

Please sign in to comment.