Implemented HTTPS by default and http flag option as argument

Change-Id: I1717da2aa4644cd73c224111e57f7c0ede9036df
This commit is contained in:
Renato Ambrosone
2025-04-01 02:55:08 +02:00
parent b0bda64b39
commit b9acee661c
2 changed files with 14 additions and 3 deletions

View File

@@ -19,6 +19,7 @@ from gnpyapi.core.exception.equipment_error import EquipmentError
from gnpyapi.core.exception.exception_handler import bad_request_handler, common_error_handler
from gnpyapi.core.exception.path_computation_error import PathComputationError
from gnpyapi.core.exception.topology_error import TopologyError
import argparse
_logger = logging.getLogger(__name__)
@@ -52,13 +53,22 @@ def _init_app():
app.register_error_handler(error_code, common_error_handler)
def main():
def main(http: bool = False):
_init_logger()
_init_app()
FlaskInjector(app=app)
app.run(host='0.0.0.0', port=8080)
if http:
app.run(host='0.0.0.0', port=8080)
else:
app.run(host='0.0.0.0', port=8080, ssl_context='adhoc')
if __name__ == '__main__':
main()
parser = argparse.ArgumentParser(description="Rest API example")
parser.add_argument("--http", action="store_true", help="run server with http instead of https")
args = parser.parse_args()
main(http=args.http)

View File

@@ -51,6 +51,7 @@ install_requires =
gnpy==2.12.1
flask>=1.1.2
Flask-Injector
pyopenssl==25.0.0
[options.extras_require]
tests =