From 16ba7070a6e040918f354b87f952cc47a7df6b5a Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 22 Jul 2021 11:19:57 +0300 Subject: feat! allow/require setting address on which to listen This will break all existing config file, of which there should be none. Sponsored-by: author --- subplot/ewww.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'subplot') diff --git a/subplot/ewww.py b/subplot/ewww.py index e30c219..a6c4c4f 100644 --- a/subplot/ewww.py +++ b/subplot/ewww.py @@ -24,10 +24,10 @@ def _write(filename, content): # Construct a URL that points to server running on localhost by # replacing the actual scheme and host with ones that work for test. def _url(ctx, url): - port = ctx["config"]["port"] + listen = ctx["config"]["listen"] c = urllib.parse.urlparse(url) host = c[1] - c = (c[0], "localhost:{}".format(port)) + c[2:] + c = (c[0], "{}".format(listen)) + c[2:] return urllib.parse.urlunparse(c), host @@ -64,9 +64,11 @@ def start_server(ctx, filename=None): logging.debug(f"Starting ewww with config file {filename}") config = get_file(filename).decode("UTF-8") config = yaml.safe_load(config) - port = config["port"] = random.randint(2000, 30000) - logging.debug(f"Picked randomly port for ewww: {config['port']}") + port = random.randint(2000, 30000) + logging.debug(f"Picked randomly port for ewww: {port}") + config["listen"] = f"localhost:{port}" ctx["config"] = config + logging.debug(f"ewww config: {config!r}") config = yaml.safe_dump(config) _write(filename, config) -- cgit v1.2.1