From a87ee06f65648444cbc3e9df80d88e5646ef9cb2 Mon Sep 17 00:00:00 2001 From: Matthew Scragg Date: Sat, 23 Jan 2016 16:04:56 -0600 Subject: [PATCH] Allow override of bound host address. Fixes #110. --- realms/__init__.py | 6 ++++-- realms/commands.py | 9 +++++---- realms/config/__init__.py | 2 ++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/realms/__init__.py b/realms/__init__.py index 27b2ce7..ee50b67 100644 --- a/realms/__init__.py +++ b/realms/__init__.py @@ -17,6 +17,7 @@ from flask.ext.login import LoginManager, current_user from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.assets import Environment, Bundle from flask_ldap_login import LDAPLoginManager +from functools import update_wrapper from werkzeug.routing import BaseConverter from werkzeug.exceptions import HTTPException from sqlalchemy.ext.declarative import declarative_base @@ -111,12 +112,14 @@ class Assets(Environment): return super(Assets, self).register(name, Bundle(*args, filters=filters, output=output)) + class MyLDAPLoginManager(LDAPLoginManager): @property def attrlist(self): # the parent method doesn't always work return None + class RegexConverter(BaseConverter): """ Enables Regex matching on endpoints """ @@ -240,8 +243,6 @@ assets.register('main.css', 'css/style.css') -from functools import update_wrapper - def with_appcontext(f): """Wraps a callback so that it's guaranteed to be executed with the script's application context. If callbacks are registered directly @@ -285,6 +286,7 @@ class AppGroup(click.Group): flask_cli = AppGroup() + @flask_cli.group() def cli(): pass diff --git a/realms/commands.py b/realms/commands.py index 326d67d..1b266f7 100644 --- a/realms/commands.py +++ b/realms/commands.py @@ -291,7 +291,8 @@ def configure(json_string): @cli.command() @click.option('--port', default=config.PORT) -def dev(port): +@click.option('--host', default=config.HOST) +def dev(port, host): """ Run development server """ green("Starting development server") @@ -302,7 +303,7 @@ def dev(port): else: yellow("Using default configuration") - create_app().run(host="0.0.0.0", + create_app().run(host=host, port=port, debug=True) @@ -332,8 +333,8 @@ def start_server(): if in_virtualenv(): prefix = get_prefix() + "/bin/" - Popen("%sgunicorn 'realms:create_app()' -b 0.0.0.0:%s -k gevent %s" % - (prefix, config.PORT, flags), shell=True, executable='/bin/bash') + Popen("%sgunicorn 'realms:create_app()' -b %s:%s -k gevent %s" % + (config.HOST, prefix, config.PORT, flags), shell=True, executable='/bin/bash') def stop_server(): diff --git a/realms/config/__init__.py b/realms/config/__init__.py index 3dba1a8..3bb8644 100644 --- a/realms/config/__init__.py +++ b/realms/config/__init__.py @@ -3,6 +3,7 @@ import json from urlparse import urlparse from realms.lib.util import in_vagrant + def update(data): conf = read() conf.update(data) @@ -72,6 +73,7 @@ DEBUG = True ASSETS_DEBUG = True SQLALCHEMY_ECHO = False +HOST = "0.0.0.0" PORT = 5000 BASE_URL = 'http://localhost' SITE_TITLE = "Realms"