Skip to content

Commit 464d8f5

Browse files
committed
add option to bind the hostname in werkzeug router
1 parent fce228e commit 464d8f5

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

ioc/extra/tornado/command.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,27 @@
22
import tornado
33
from tornado.httpserver import HTTPServer
44

5-
65
class StartCommand(Command):
7-
8-
def __init__(self, application):
6+
def __init__(self, application, router):
97
self.application = application
8+
self.router = router
109

1110
def initialize(self, parser):
1211
parser.description = 'Start tornado integrated server'
1312
parser.add_argument('--address', '-a', default='0.0.0.0', help="the host to bind the port")
1413
parser.add_argument('--port', '-p', default=5000, type=int, help="the port to listen")
1514
parser.add_argument('--processes', '-np', default=1, type=int, help="number of processes to start (0=cores available)")
15+
parser.add_argument('--bind', '-b', default="localhost", type=str, help="bind the router to the provided named (default=localhost)")
1616

1717
def execute(self, args, output):
1818
output.write("Starting tornado %s:%s\n" % (args.address, args.port))
1919

20+
self.router.bind(args.bind)
21+
2022
server = HTTPServer(self.application)
2123
server.bind(args.port, args.address)
24+
server.start(args.processes)
2225

2326
output.write("Waiting for connection...\n")
24-
server.start(args.processes)
2527

2628
tornado.ioloop.IOLoop.instance().start()

ioc/extra/tornado/resources/config/services.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ services:
2222
class: ioc.extra.tornado.command.StartCommand
2323
arguments:
2424
- '@ioc.extra.tornado.application'
25+
- '@ioc.extra.tornado.router'
26+
2527
tags:
2628
command:
2729
- { name: 'tornado:start' }

ioc/extra/tornado/router.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def getlist(self, name):
5252

5353
class Router(object):
5454
def __init__(self, url_map=None):
55+
5556
self._url_map = url_map or Map([])
5657
self._view_functions = {}
5758
self._adapter = None
@@ -69,6 +70,9 @@ def add(self, name, pattern, view_func, defaults=None, subdomain=None, methods=N
6970

7071
self._adapter = None
7172

73+
def bind(self, hostname):
74+
self._adapter = self._url_map.bind(hostname)
75+
7276
def adapter(self):
7377
if not self._adapter:
7478
self._adapter = self._url_map.bind("localhost")

0 commit comments

Comments
 (0)