Add ability to set web-server port via API #21

Closed
nzjrs opened this Issue Jul 30, 2010 · 7 comments

Comments

Projects
None yet
3 participants

nzjrs commented Jul 30, 2010

Hi,

I am using web.py as an embedded webserver in my app. Because there is no way to set the port served programatically I have to do this

    import sys; sys.argv[1] = '8080'    #Yuck
    self.app = web.application(xxxx)
    thread.start_new_thread(self.app.run, ())

Otherwise webpy assumes the first command line argument it its port (which it is not as my app has many other command line args)

Contributor

anandology commented Aug 26, 2010

How about making it take from web.config if specified? Something like this:

web.config.default_port = 8090
app.run()

nzjrs commented Aug 26, 2010

I guess that would be sufficient, however I would prefer it be per application (config is global, right?).

Although not needed in my case, someone else might wish to run multiple servers on different ports.

nzjrs commented Aug 26, 2010

Actually I just saw that config seems to hold other global state (smtp config for example), so there is precident.

web.config.default_port makes sense in that case.

Contributor

anandology commented Aug 26, 2010

we might want to support specifying the interface too. 127.0.0.1 to bind only on localhost.
Should we call it default_bind_address?

web.ctx.default_bind_address = '127.0.0.1:9000'

or just port:

web.ctx.default_bind_address = 9000

nzjrs commented Aug 26, 2010

How about just calling it interface?

web.ctx.default_interface = 127.0.0.1:9000

And, in the port only case

web.ctx.default_interface = :9000

(i.e. starts with ':')

Contributor

anandology commented Nov 12, 2010

This can be solved by calling runsimple like this.

if __name__ == "__main__":
   web.httpserver.runsimple(app.wsgifunc(), ("0.0.0.0", 8888))
Contributor

serverhorror commented Mar 17, 2011

For the port only case in web.ctx.default_interface

web.ctx.default_interface = ::1

Do I now listen on port 1 with the default interface or on IPv6 loopback and the default port? Of course this:

web.ctx.default_interface = '[::1]'

would make it clear for IPv6.

I'd like a a default_address (as interfaces can have multiple addresses) and a default_port. Keeping with the explicit is better than implicit (pep-0020, second line in the zen of python) - yes I'm being a smartass here. Sorry :)

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment