diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..2857c89e --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +################################################################################ +# This .gitignore file was automatically created by Microsoft(R) Visual Studio. +################################################################################ + +/TestEnvironment +/.vs diff --git a/demofile.text b/demofile.text new file mode 100644 index 00000000..8410348b --- /dev/null +++ b/demofile.text @@ -0,0 +1 @@ +This is a demo file read diff --git a/oldServer.py b/oldServer.py new file mode 100644 index 00000000..107646bf --- /dev/null +++ b/oldServer.py @@ -0,0 +1,21 @@ +import os +import http.server +import socketserver + +from http import HTTPStatus + + +class Handler(http.server.SimpleHTTPRequestHandler): + def do_GET(self): + self.send_response(HTTPStatus.OK) + self.end_headers() + msg = 'Hello, FISH ! you requested %s' % (self.path) + f = open("static/demofile2.txt", "r") + msg = f.read() + self.wfile.write(msg.encode()) + + +port = int(os.getenv('PORT', 8080)) +print('Listening on port %s' % (port)) +httpd = socketserver.TCPServer(('', port), Handler) +httpd.serve_forever() diff --git a/requirements.txt b/requirements.txt index e69de29b..c2d81ef2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask==2.0.2 +Waitress==2.0.0 \ No newline at end of file diff --git a/server.py b/server.py index 430d1dc7..3b9ef7d9 100644 --- a/server.py +++ b/server.py @@ -1,19 +1,22 @@ -import os -import http.server -import socketserver +from flask import Flask -from http import HTTPStatus +# Create an instance of the Flask class that is the WSGI application. +# The first argument is the name of the application module or package, +# typically __name__ when using a single module. +app = Flask(__name__) +# Flask route decorators map / and /hello to the hello function. +# To add other resources, create functions that generate the page contents +# and add decorators to define the appropriate resource locators for them. -class Handler(http.server.SimpleHTTPRequestHandler): - def do_GET(self): - self.send_response(HTTPStatus.OK) - self.end_headers() - msg = 'Hello! you requested %s' % (self.path) - self.wfile.write(msg.encode()) +@app.route('/') +@app.route('/hello') +def hello(): + # Render the page + return "Hello Python! Sample Python Waitress brings flask so its working" - -port = int(os.getenv('PORT', 80)) -print('Listening on port %s' % (port)) -httpd = socketserver.TCPServer(('', port), Handler) -httpd.serve_forever() +if __name__ == '__main__': + from waitress import serve + serve(app, host="0.0.0.0", port=8080) + # Run the app server on localhost:4449 + # app.run('localhost', 4449) diff --git a/static/demofile2.txt b/static/demofile2.txt new file mode 100644 index 00000000..3a451c55 --- /dev/null +++ b/static/demofile2.txt @@ -0,0 +1 @@ +This is demo reading file2 diff --git a/static/index.html b/static/index.html new file mode 100644 index 00000000..1e107669 --- /dev/null +++ b/static/index.html @@ -0,0 +1 @@ + This is the index file diff --git a/static/test.html b/static/test.html new file mode 100644 index 00000000..f8cd0c84 --- /dev/null +++ b/static/test.html @@ -0,0 +1 @@ + Testing testing 1 2 3 diff --git a/test.html b/test.html new file mode 100644 index 00000000..88e01765 --- /dev/null +++ b/test.html @@ -0,0 +1 @@ + Test static html