Define http port via env vars as well
This commit is contained in:
		@@ -214,7 +214,7 @@ without any argument, on port 8080.
 | 
				
			|||||||
morss
 | 
					morss
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
You can change the port like this `morss 9000`.
 | 
					You can change the port using environment variables like this `PORT=9000 morss`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#### Passing arguments
 | 
					#### Passing arguments
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,7 +12,7 @@ import wsgiref.simple_server
 | 
				
			|||||||
import wsgiref.handlers
 | 
					import wsgiref.handlers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PORT = 8080
 | 
					PORT = int(os.getenv('PORT', 8080))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def isInt(string):
 | 
					def isInt(string):
 | 
				
			||||||
@@ -26,7 +26,7 @@ def isInt(string):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
def main():
 | 
					def main():
 | 
				
			||||||
    if 'REQUEST_URI' in os.environ:
 | 
					    if 'REQUEST_URI' in os.environ:
 | 
				
			||||||
        # mod_cgi
 | 
					        # mod_cgi (w/o file handler)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        app = wsgi.cgi_app
 | 
					        app = wsgi.cgi_app
 | 
				
			||||||
        app = wsgi.cgi_dispatcher(app)
 | 
					        app = wsgi.cgi_dispatcher(app)
 | 
				
			||||||
@@ -35,19 +35,8 @@ def main():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        wsgiref.handlers.CGIHandler().run(app)
 | 
					        wsgiref.handlers.CGIHandler().run(app)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    elif len(sys.argv) <= 1 or isInt(sys.argv[1]):
 | 
					    elif len(sys.argv) <= 1:
 | 
				
			||||||
        # start internal (basic) http server
 | 
					        # start internal (basic) http server (w/ file handler)
 | 
				
			||||||
 | 
					 | 
				
			||||||
        if len(sys.argv) > 1 and isInt(sys.argv[1]):
 | 
					 | 
				
			||||||
            argPort = int(sys.argv[1])
 | 
					 | 
				
			||||||
            if argPort > 0:
 | 
					 | 
				
			||||||
                port = argPort
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            else:
 | 
					 | 
				
			||||||
                raise MorssException('Port must be positive integer')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            port = PORT
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        app = wsgi.cgi_app
 | 
					        app = wsgi.cgi_app
 | 
				
			||||||
        app = wsgi.cgi_file_handler(app)
 | 
					        app = wsgi.cgi_file_handler(app)
 | 
				
			||||||
@@ -56,7 +45,7 @@ def main():
 | 
				
			|||||||
        app = wsgi.cgi_encode(app)
 | 
					        app = wsgi.cgi_encode(app)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        print('Serving http://localhost:%s/' % port)
 | 
					        print('Serving http://localhost:%s/' % port)
 | 
				
			||||||
        httpd = wsgiref.simple_server.make_server('', port, app)
 | 
					        httpd = wsgiref.simple_server.make_server('', PORT, app)
 | 
				
			||||||
        httpd.serve_forever()
 | 
					        httpd.serve_forever()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user