Add argparse'd --port option, for Docker

This commit is contained in:
Darryl Nixon 2023-05-22 10:18:09 -07:00
parent feeebd8fe5
commit fb002fcca2
2 changed files with 8 additions and 3 deletions

View file

@ -27,7 +27,7 @@ When that's done, get `binhop` running with something like:
git clone https://github.com/darrylnixon/binhop.git git clone https://github.com/darrylnixon/binhop.git
cd binhop cd binhop
pip install -r requirements.txt pip install -r requirements.txt
./binhop.py ./binhop.py [--port <port, default: 8080>]
``` ```
Once running, browse to [http://localhost:8080](http://localhost:8080) and upload a blob. Once running, browse to [http://localhost:8080](http://localhost:8080) and upload a blob.

View file

@ -9,6 +9,7 @@ import os
from aiohttp_compress import compress_middleware from aiohttp_compress import compress_middleware
from aiohttp import web from aiohttp import web
from typing import List, Tuple, Dict, Union from typing import List, Tuple, Dict, Union
import argparse
async def scan_file(filename: str, base_dir: str) -> List: async def scan_file(filename: str, base_dir: str) -> List:
@ -132,6 +133,10 @@ async def serve_static(request: web.Request) -> Union[web.FileResponse, web.HTTP
async def main() -> None: async def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--port", "-p", type=int, default=8080, help="Port to serve on")
args = parser.parse_args()
app = web.Application() app = web.Application()
app.middlewares.append(compress_middleware) app.middlewares.append(compress_middleware)
@ -145,10 +150,10 @@ async def main() -> None:
runner = web.AppRunner(app) runner = web.AppRunner(app)
await runner.setup() await runner.setup()
site = web.TCPSite(runner, "localhost", 8080) site = web.TCPSite(runner, "0.0.0.0", args.port)
await site.start() await site.start()
print("binhop is running at http://localhost:8080") print(f"binhop is running at http://localhost:{args.port}")
await asyncio.Event().wait() await asyncio.Event().wait()