@@ -93,7 +93,7 @@ def add_arguments(self, parser):
9393 parser .add_argument (
9494 "addrport" ,
9595 nargs = "?" ,
96- default = "127.0.0.1:8000 " ,
96+ default = "" ,
9797 help = "Optional port number, or ipaddr:port [default=`127.0.0.1:8000`]" ,
9898 )
9999
@@ -122,18 +122,26 @@ def handle(self, *args, **options):
122122 init_periodic = options ["periodic" ],
123123 )
124124
125- # With no argument, bind to 127.0.0.1 to match runserver, gunicorn, etc.
126- # If specifying a port (but no address), bind to 0.0.0.0.
125+ # With no argument, bind to 127.0.0.1:8000 to match runserver, gunicorn, etc.
127126 address = "127.0.0.1"
128127 port = 8000
128+ # Default to the GRANIAN_ environment variables if set.
129+ if p := os .getenv ("GRANIAN_PORT" ):
130+ # Match gunicorn's behavior of binding to 0.0.0.0 when port is in the env.
131+ address = "0.0.0.0"
132+ port = int (p )
133+ if a := os .getenv ("GRANIAN_HOST" ):
134+ address = a
135+ # Then check to see if an address/port was specified on the command line.
129136 if options ["addrport" ].isdigit ():
137+ # If specifying a port (but no address), bind to 0.0.0.0.
130138 address = "0.0.0.0"
131139 port = int (options ["addrport" ])
132140 elif ":" in options ["addrport" ]:
133141 a , p = options ["addrport" ].rsplit (":" , 1 )
134142 address = a or "0.0.0.0"
135143 port = int (p )
136- else :
144+ elif options [ "addrport" ] :
137145 address = options ["addrport" ]
138146
139147 reload_paths = []
0 commit comments