diff options
author | xengineering <mail2xengineering@protonmail.com> | 2021-03-07 09:59:14 +0100 |
---|---|---|
committer | xengineering <mail2xengineering@protonmail.com> | 2021-03-07 09:59:14 +0100 |
commit | 47b30cea327420ed6f17ccc6fd521ad89f4b4e4f (patch) | |
tree | a354a4adc5f6d2f004890750201f958db9e6a372 | |
parent | f48ce5deb19d83e6d5e87f51c59e538f4b66d79e (diff) | |
download | web-template-47b30cea327420ed6f17ccc6fd521ad89f4b4e4f.tar web-template-47b30cea327420ed6f17ccc6fd521ad89f4b4e4f.tar.zst web-template-47b30cea327420ed6f17ccc6fd521ad89f4b4e4f.zip |
Add Makefiles and implement Config Parser in server.py
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | src/Makefile | 8 | ||||
-rw-r--r-- | src/config.ini | 20 | ||||
-rwxr-xr-x[-rw-r--r--] | src/server.py | 17 |
4 files changed, 51 insertions, 2 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8814205 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +# vim: shiftwidth=4 tabstop=4 noexpandtab + +all: + echo "make all - nothing to do in this pure python project ;)" + +debug: + make -C src/ debug + diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..43ea379 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,8 @@ +# vim: shiftwidth=4 tabstop=4 noexpandtab + +all: + echo "make all - nothing to do in this pure python project ;)" + +debug: + ./server.py + diff --git a/src/config.ini b/src/config.ini index 2a67194..c91e9ce 100644 --- a/src/config.ini +++ b/src/config.ini @@ -1,5 +1,23 @@ +; This section is for the configuration of xengineerings web-template. +; You can use additional sections for other purposes. [web-template] + +; Choose a project_name containing only characters and underscores. +; This project_name is used for the systemd service of your +; application (/etc/systemd/system/<project_name>.service) and the +; folder in /opt where your application is deployed +; (/opt/<project_name>/). project_name=my_web_server -friendly_project_name=My first web Server + +; Choose a project_description to be used for the systemd unit. +project_description=A template for Web Applications + +; Select a linux user and group for execution +user=http +group=http + +; Select an IP address and port to bind to. +address=127.0.0.1 +port=8080 diff --git a/src/server.py b/src/server.py index 2caddd6..37fcb51 100644..100755 --- a/src/server.py +++ b/src/server.py @@ -2,6 +2,7 @@ # vim: shiftwidth=4 tabstop=4 expandtab +import configparser import waitress from flask import Flask @@ -14,8 +15,22 @@ def index(): return app.send_static_file("index.html") +def load_config(): + """Load ./config.ini File and read web-template Section""" + + retval = {} + + config = configparser.ConfigParser() + config.read("config.ini") + for option in config.options("web-template"): + retval[option] = config.get("web-template", option) + + return retval # dictionary with all options from web-template section + + if __name__ == '__main__': - waitress.serve(app, listen="127.0.0.1:8080") # production server / bind to port + config = load_config() + waitress.serve(app, listen="{}:{}".format(config["address"], config["port"])) # production server / bind to port #serve(app, unix_socket='/run/web-template/unix.sock') # production server / unix domain socket #app.run() # debug server - NOT FOR PRODUCTION! |