From 854d822acce56a8599c7001af2f8a2b0e2bbea9e Mon Sep 17 00:00:00 2001 From: root Date: Fri, 26 Apr 2019 16:03:42 +0000 Subject: [PATCH] changing server to use flask --- .vscode/launch.json | 18 +++++++++++++++--- .vscode/settings.json | 3 --- README.md | 10 +++++----- server.py => app.py | 14 +++++--------- requirements.txt | 1 + index.html => static/index.html | 0 6 files changed, 26 insertions(+), 20 deletions(-) delete mode 100644 .vscode/settings.json rename server.py => app.py (58%) create mode 100644 requirements.txt rename index.html => static/index.html (100%) diff --git a/.vscode/launch.json b/.vscode/launch.json index b02d7c4..bed8fa4 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,11 +5,23 @@ "version": "0.2.0", "configurations": [ { - "name": "Launch Server", + "name": "Python: Flask", "type": "python", "request": "launch", - "program": "${workspaceFolder}/server.py", - "console": "integratedTerminal" + "module": "flask", + "env": { + "FLASK_APP": "app.py", + "FLASK_ENV": "development", + "FLASK_DEBUG": "0" + }, + "args": [ + "run", + "--host","0.0.0.0", + "--port","9000", + "--no-debugger", + "--no-reload" + ], + "jinja": true } ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 58eb1df..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "python.jediEnabled": false -} \ No newline at end of file diff --git a/README.md b/README.md index c2fff4b..ba41c6f 100644 --- a/README.md +++ b/README.md @@ -15,15 +15,15 @@ Some things to try: 2. Try adding some code and check out the language features. 2. **Terminal:** Press ctrl+shift+\` and type `uname` and or other Linux commands from the terminal window. 3. **Build, Run, and Debug:** - 1. Open `sever.py` - 2. Add a breakpoint (e.g. on line 13). + 1. Open `app.py` + 2. Add a breakpoint (e.g. on line 9). 3. Press F5 to launch the app in the container. - 4. Once the breakpoint is hit, try hovering over variables, examining locals, and more. + 4. Once the breakpoint is hit, try hovering over variables (e.g. the app variable on line 7), examining locals, and more. 5. Continue, then open a local browser and go to `http://localhost:9000` and note you can connect to the server in the container 4. **Forward another port:** 1. Stop debugging and remove the breakpoint. - 2. Open `sever.py` - 3. Change the server port to 5000. (`PORT = 5000`) + 2. Open `.vscode/launch.json` + 3. Change the server port to 5000 on line 20. (`"--port","5000"`) 4. Press F5 to launch the app in the container. 5. Press F1 and run the **Remote-Containers: Forward Port...** command. 6. Select port 5000. diff --git a/server.py b/app.py similarity index 58% rename from server.py rename to app.py index 1c481b4..8c27ec7 100644 --- a/server.py +++ b/app.py @@ -3,13 +3,9 @@ # Licensed under the MIT License. See LICENSE in the project root for license information. #----------------------------------------------------------------------------------------- -import socketserver -import http.server +from flask import Flask +app = Flask(__name__) -RequestHandler = http.server.SimpleHTTPRequestHandler - -PORT = 5000 - -with socketserver.TCPServer(("", PORT), RequestHandler) as httpd: - print("Server running on port", PORT) - httpd.serve_forever() \ No newline at end of file +@app.route("/") +def hello(): + return app.send_static_file("index.html") diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8ab6294 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +flask \ No newline at end of file diff --git a/index.html b/static/index.html similarity index 100% rename from index.html rename to static/index.html