From 0e5630f33a1c50d2ef4faa6685e25eb0ffd689c8 Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Wed, 6 Apr 2022 14:11:52 -0600 Subject: [PATCH] Add ability to listen on unix sockets Introduces a way to tell the app to listen on unix socket instead of host:port. Fixes #436 --- app/routes.py | 7 +++++++ run | 14 ++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/routes.py b/app/routes.py index f4308e1..658961a 100644 --- a/app/routes.py +++ b/app/routes.py @@ -512,6 +512,11 @@ def run_app() -> None: default='127.0.0.1', metavar='', help='Specifies the host address to use (default 127.0.0.1)') + parser.add_argument( + '--unix-socket', + default='', + metavar='', + help='Listen for app on unix socket instead of host:port') parser.add_argument( '--debug', default=False, @@ -562,5 +567,7 @@ def run_app() -> None: if args.debug: app.run(host=args.host, port=args.port, debug=args.debug) + elif args.unix_socket: + waitress.serve(app, unix_socket=args.unix_socket) else: waitress.serve(app, listen="{}:{}".format(args.host, args.port)) diff --git a/run b/run index 2cc3cfe..0a2ed37 100755 --- a/run +++ b/run @@ -3,7 +3,7 @@ # ./run # Runs the full web app # ./run test # Runs the testing suite -set -eu +set -e SCRIPT_DIR="$(CDPATH= command cd -- "$(dirname -- "$0")" && pwd -P)" @@ -24,7 +24,13 @@ if [ "$SUBDIR" = "test" ]; then pytest -sv else mkdir -p "$STATIC_FOLDER" - python3 -um app \ - --host "${ADDRESS:-0.0.0.0}" \ - --port "${PORT:-"${EXPOSE_PORT:-5000}"}" + + if [ ! -z "$UNIX_SOCKET" ]; then + python3 -um app \ + --unix-socket "$UNIX_SOCKET" + else + python3 -um app \ + --host "${ADDRESS:-0.0.0.0}" \ + --port "${PORT:-"${EXPOSE_PORT:-5000}"}" + fi fi