chg: [server] configurable port, common exceptions

This commit is contained in:
Esa Jokinen 2021-09-22 09:50:34 +03:00
parent 650e0f7fec
commit 5320323840

View file

@ -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)