8000 Add port to examples documentation. by neiljp · Pull Request #842 · hugapi/hug · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add port to examples documentation. #842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions hug/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,11 @@ def set_not_found_handler(self, handler, version=None):

self.not_found_handlers[version] = handler

def documentation(self, base_url=None, api_version=None, prefix=""):
def documentation(self, base_url=None, api_version=None, prefix="", port=None):
"""Generates and returns documentation for this API endpoint"""
documentation = OrderedDict()
base_url = self.base_url if base_url is None else base_url
port_suffix = "" if port is None else ":" + str(port)
overview = self.api.doc
if overview:
documentation["overview"] = overview
Expand Down Expand Up @@ -263,7 +264,7 @@ def documentation(self, base_url=None, api_version=None, prefix=""):
doc.get(method, None),
version=version,
prefix=prefix,
base_url=router_base_url,
base_url=router_base_url + port_suffix,
url=url,
)
documentation["handlers"] = version_dict
Expand All @@ -272,9 +273,9 @@ def documentation(self, base_url=None, api_version=None, prefix=""):
def serve(self, host="", port=8000, no_documentation=False, display_intro=True):
"""Runs the basic hug development server against this API"""
if no_documentation:
api = self.server(None)
api = self.server(None, port=port)
else:
api = self.server()
api = self.server(port=port)

if display_intro:
print(INTRO)
Expand Down Expand Up @@ -314,7 +315,7 @@ def determine_version(self, request, api_version=None):

return next(iter(request_version or (None,)))

def documentation_404(self, base_url=None):
def documentation_404(self, base_url=None, port=None):
"""Returns a smart 404 page that contains documentation for the written API"""
base_url = self.base_url if base_url is None else base_url

Expand All @@ -329,7 +330,7 @@ def handle_404(request, response, *args, **kwargs):
"Here's a definition of the API to help you get going :)"
)
to_return["documentation"] = self.documentation(
base_url, self.determine_version(request, False), prefix=url_prefix
base_url, self.determine_version(request, False), prefix=url_prefix, port=port
)

if self.output_format == hug.output_format.json:
Expand All @@ -356,15 +357,15 @@ def version_router(
request, response, api_version=api_version, **kwargs
)

def server(self, default_not_found=True, base_url=None):
def server(self, default_not_found=True, base_url=None, port=None):
"""Returns a WSGI compatible API server for the given Hug API module"""
falcon_api = self.falcon = falcon.API(middleware=self.middleware)
if not self.api.future:
falcon_api.req_options.keep_blank_qs_values = False
falcon_api.req_options.auto_parse_qs_csv = True
falcon_api.req_options.strip_url_path_trailing_slash = True

default_not_found = self.documentation_404() if default_not_found is True else None
default_not_found = self.documentation_404(port=port) if default_not_found is True else None
base_url = self.base_url if base_url is None else base_url

not_found_handler = default_not_found
Expand Down
0