Skip to content
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

Add: allow indicate that we are behind a proxy #16

Merged
merged 1 commit into from
Apr 19, 2020
Merged
Show file tree
Hide file tree
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
16 changes: 11 additions & 5 deletions bananas_api/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def set_death_signal():
libc.prctl(PR_SET_PDEATHSIG, signal.SIGTERM, 0, 0, 0)


async def _run_tusd(host, tusd_port, web_port, base_path):
command = (
async def _run_tusd(host, tusd_port, web_port, base_path, behind_proxy=False):
command = [
f"tusd",
f"--host",
f"{host}",
Expand All @@ -60,7 +60,10 @@ async def _run_tusd(host, tusd_port, web_port, base_path):
f"pre-create,post-create,post-finish",
f"--base-path",
f"{base_path}",
)
]
if behind_proxy:
command += ["--behind-proxy"]

tusd_proc = await asyncio.create_subprocess_exec(
command[0],
*command[1:],
Expand All @@ -86,6 +89,9 @@ def click_logging():
)
@click.option("--web-port", help="Port of the web server.", default=80, show_default=True, metavar="PORT")
@click.option("--tusd-port", help="Port of the tus server.", default=1080, show_default=True, metavar="PORT")
@click.option(
"--behind-proxy", help="Respect X-Forwarded-* and similar headers which may be set by proxies.", is_flag=True
)
@common.click_reload_secret
@click_cleanup_graceperiod
@click_storage
Expand All @@ -94,7 +100,7 @@ def click_logging():
@click_user_session
@click_user_github
@click.option("--validate", help="Only validate BaNaNaS files and exit.", is_flag=True)
def main(bind, web_port, tusd_port, validate):
def main(bind, web_port, tusd_port, validate, behind_proxy):
"""
Start the BaNaNaS API.

Expand Down Expand Up @@ -124,7 +130,7 @@ def main(bind, web_port, tusd_port, validate):
for host in bind:
if ":" in host:
host = f"[{host}]"
loop.create_task(_run_tusd(host, tusd_port, web_port, "/new-package/tus/"))
loop.create_task(_run_tusd(host, tusd_port, web_port, "/new-package/tus/", behind_proxy))

# Start aiohttp server
web.run_app(webapp, host=bind, port=web_port, access_log_class=ErrorOnlyAccessLogger)
Expand Down
2 changes: 1 addition & 1 deletion wishlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
- Allow setting versions to "new-games" / "savegames-only" if you like to
- Set version members to "" should delete them (so that package data becomes active). None is used for "unchanged".
- Endpoints to get list of licenses and branches
- Implement client-ids and restrict redirect-uris based on that
- Check that \r\n are translated to \n properly