From 38a4e0839c2a2a13abae481977249a8ffba63899 Mon Sep 17 00:00:00 2001 From: "Harish.K" Date: Sat, 6 Jun 2020 23:22:35 +0530 Subject: [PATCH] Misc usability fixes 1. Added binding address in config 2. Added missing dependency sqlalchemy 3. Added permanent redirect to index.html --- config.sample | 1 + requirements.txt | 1 + run.sh | 3 ++- server.py | 6 ++++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/config.sample b/config.sample index e3d59a3..9501139 100644 --- a/config.sample +++ b/config.sample @@ -1,2 +1,3 @@ DB_CONNECTION=postgresql://postgres@localhost/postgres +BIND_ADDRESS=127.0.0.1:8000 diff --git a/requirements.txt b/requirements.txt index ee1f55f..aa824e6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ falcon==1.4.1 gunicorn==19.9.0 +sqlalchemy diff --git a/run.sh b/run.sh index c1ce1a1..c8e0707 100755 --- a/run.sh +++ b/run.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash [ -f ./config ] && . ./config && export DB_CONNECTION -gunicorn server:api +bindAddress=${BIND_ADDRESS:-'127.0.0.1:8000'} +gunicorn server:api -b $bindAddress "$@" diff --git a/server.py b/server.py index d871d05..93b045d 100644 --- a/server.py +++ b/server.py @@ -22,6 +22,12 @@ class QResource: resp.set_header('content-type', 'application/json; charset=UTF-8') resp.body = json.dumps( data, default=str ) + +class RedirectingResource: + def on_get(self, req, resp): + raise falcon.HTTPMovedPermanently('/index.html') + api = falcon.API() +api.add_route('/', RedirectingResource()) api.add_static_route('/', os.path.dirname(os.path.realpath(__file__)) + '/static' ) api.add_route('/api/data', QResource())