-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to Flask to enable live updates
- Loading branch information
Abhay Saxena
committed
Apr 3, 2019
1 parent
5a657c6
commit 788da79
Showing
3 changed files
with
17 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |