swagger-http-server: add a --port argument

pull/977/head
Richard van der Hoff 8 years ago
parent 6d7f543612
commit 459f4b953d

@ -22,8 +22,6 @@ import os
import SimpleHTTPServer import SimpleHTTPServer
import SocketServer import SocketServer
PORT = 8000
# Thanks to http://stackoverflow.com/a/13354482 # Thanks to http://stackoverflow.com/a/13354482
class MyHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): class MyHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def end_headers(self): def end_headers(self):
@ -37,12 +35,21 @@ class MyHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
if __name__ == '__main__': if __name__ == '__main__':
scripts_dir = os.path.dirname(os.path.abspath(__file__)) scripts_dir = os.path.dirname(os.path.abspath(__file__))
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('swagger_dir', nargs='?', parser.add_argument(
default=os.path.join(scripts_dir, 'swagger')) '--port', '-p', nargs=1,
type=int, default=8000,
help='TCP port to listen on (default: %(default)s)',
)
parser.add_argument(
'swagger_dir', nargs='?',
default=os.path.join(scripts_dir, 'swagger'),
help='directory to serve (default: %(default)s)',
)
args = parser.parse_args() args = parser.parse_args()
os.chdir(args.swagger_dir) os.chdir(args.swagger_dir)
httpd = SocketServer.TCPServer(("localhost", PORT), MyHTTPRequestHandler) httpd = SocketServer.TCPServer(("localhost", args.port),
print "Serving at http://localhost:%i/api-docs.json" % PORT MyHTTPRequestHandler)
print "Serving at http://localhost:%i/api-docs.json" % args.port
httpd.serve_forever() httpd.serve_forever()

Loading…
Cancel
Save