Skip to content

Commit 073a434

Browse files
committed
Fix webservice interactions with Docker
1 parent f390e7f commit 073a434

File tree

4 files changed

+399
-2
lines changed

4 files changed

+399
-2
lines changed

misc/_webservice.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import subprocess
1717
import sys
1818
import time
19+
import urllib
1920
from functools import partial
2021
from operator import getitem
2122
from pathlib import Path
@@ -29,6 +30,17 @@
2930

3031
from ocrmypdf._defaults import DEFAULT_ROTATE_PAGES_THRESHOLD
3132

33+
34+
def get_host_url_with_port(port: int) -> str:
35+
"""Get the host URL for the web service. Hacky."""
36+
host_url = st.context.headers["host"]
37+
try:
38+
host, _streamlit_port = host_url.split(":", maxsplit=1)
39+
except ValueError:
40+
host = host_url
41+
return f"//{host}:{port}" # Use the same protocol
42+
43+
3244
st.title("OCRmyPDF Web Service")
3345

3446
if not which("ttyd"):
@@ -218,7 +230,7 @@
218230
ttyd_proc = subprocess.Popen(
219231
ttyd_args + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE
220232
)
221-
iframe(src=f"http://localhost:{port}", height=400)
233+
iframe(src=get_host_url_with_port(port), height=400)
222234

223235
while ttyd_proc.poll() is None:
224236
ttyd_proc.poll()

misc/webservice.py

100644100755
+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python
12
# SPDX-FileCopyrightText: 2025 James R. Barlow
23
# SPDX-License-Identifier: AGPL-3.0-or-later
34

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,5 @@ dev = [
163163
"pymupdf>=1.24.14",
164164
"streamlit-pdf-viewer>=0.0.19",
165165
"streamlit>=1.40.2",
166+
"ipykernel>=6.29.5",
166167
]

0 commit comments

Comments
 (0)