From e4ad81cde0304267aaf12366bf2f64dd21995df0 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Thu, 20 Mar 2014 16:25:15 +0100 Subject: [PATCH] exit if no website(s) are configured and remove default host --- isso/__init__.py | 8 +++++++- isso/core.py | 3 ++- isso/utils/__init__.py | 8 ++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/isso/__init__.py b/isso/__init__.py index 933081d..168b99e 100644 --- a/isso/__init__.py +++ b/isso/__init__.py @@ -167,7 +167,9 @@ def make_app(conf=None, threading=True, multiprocessing=False, uwsgi=False): logger.info("connected to %s", host) break else: - logger.warn("unable to connect to %s", ", ".join(conf.getiter("general", "host"))) + logger.warn("unable to connect to your website, Isso will probably not " + "work correctly. Please make sure, Isso can reach your " + "website via HTTP(S).") wrapper = [local_manager.make_middleware] @@ -215,6 +217,10 @@ def main(): migrate.disqus(db.SQLite3(dbpath, conf), args.dump) sys.exit(0) + if not any(conf.getiter("general", "host")): + logger.error("No website(s) configured, Isso won't work.") + sys.exit(1) + if conf.get("server", "listen").startswith("http://"): host, port, _ = parse.host(conf.get("server", "listen")) try: diff --git a/isso/core.py b/isso/core.py index b47c465..c3f3fd2 100644 --- a/isso/core.py +++ b/isso/core.py @@ -114,7 +114,8 @@ class Config: "[general]", "name = ", "dbpath = /tmp/isso.db", - "host = http://localhost:8080/", "max-age = 15m", + "host = ", + "max-age = 15m", "notify = ", "[moderation]", "enabled = false", diff --git a/isso/utils/__init__.py b/isso/utils/__init__.py index 6c94f15..8dd7e4d 100644 --- a/isso/utils/__init__.py +++ b/isso/utils/__init__.py @@ -125,10 +125,18 @@ class JSONResponse(Response): def origin(hosts): + """ + Return a function that returns a valid HTTP Origin or localhost + if none found. + """ hosts = [x.rstrip("/") for x in hosts] def func(environ): + + if not hosts: + return "http://localhost/" + for host in hosts: if environ.get("HTTP_ORIGIN", None) == host: return host