From 5320323840801e193c7284b1ad47046ca78af06c Mon Sep 17 00:00:00 2001 From: Esa Jokinen Date: Wed, 22 Sep 2021 09:50:34 +0300 Subject: [PATCH] chg: [server] configurable port, common exceptions --- bin/server.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/bin/server.py b/bin/server.py index 301fac1..d256c6a 100644 --- a/bin/server.py +++ b/bin/server.py @@ -7,6 +7,9 @@ import falcon from wsgiref.simple_server import make_server import json +# Configuration +port = 8000 + runPath = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(runPath, "..")) from lib.cpeguesser import CPEGuesser @@ -36,6 +39,12 @@ if __name__ == '__main__': app = falcon.App() app.add_route('/search', Search()) - with make_server('', 8000, app) as httpd: - print('Serving on port 8000...') - httpd.serve_forever() + try: + with make_server('', port, app) as httpd: + print(f"Serving on port {port}...") + httpd.serve_forever() + except OSError as e: + print (e) + sys.exit(1) + except KeyboardInterrupt: + sys.exit(0)