Proxy kiwix-serve through this app instead of linking to it directly
CI / check (push) Successful in 39s
CI / deploy (push) Successful in 12s

map.priesol.net sits behind a reverse proxy that only forwards to
maptool itself, so the previous approach (publish kiwix-serve's port,
link the browser straight at it) had no address a real browser could
ever reach — not just a Docker-internal hostname as first assumed, but
no host/port combination at all works from outside.

GET /kiwix/* now proxies to kiwix-serve (Kiwix.proxy in
lib/maptool/kiwix.rb, a plain Net::HTTP passthrough), and the kiwix
service runs with --urlRootLocation=/kiwix so every link/asset it
emits already carries that same prefix and needs no rewriting
(confirmed against libkiwix/internalServer.cpp, which strips this
exact prefix off incoming requests). Drops the port-publishing
approach from the previous commit entirely.
This commit is contained in:
randy committed 2026-09-09 15:29:08 +02:00
1 parent 9997a8a8c0
commit 5ff9b113d9
7 files changed
+107 -51

No files matched your search

+30
View File
@@ -15,4 +15,34 @@ class KiwixTest < Minitest::Test
def test_reachable_is_false_when_nothing_is_listening
refute Maptool::Kiwix.reachable?("http://127.0.0.1:1", open_timeout: 1)
end
# A bare TCPServer stub (not WEBrick — not a project dependency, and this
# only needs to echo back what request line it received) confirms .proxy
# actually builds the target URL from path + query_string correctly, not
# just that it can complete *a* request (already covered by nothing here
# exercising a wrong path/query, unlike .reachable? which only ever hits
# "/").
def test_proxy_forwards_path_and_query_and_returns_the_response
server = TCPServer.new("127.0.0.1", 0)
port = server.addr[1]
request_line = nil
thread = Thread.new do
client = server.accept
request_line = client.gets
client.print("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 2\r\n\r\nhi")
client.close
end
response = Maptool::Kiwix.proxy("http://127.0.0.1:#{port}", "/kiwix/search", "pattern=&latitude=1")
thread.join
server.close
assert_equal "GET /kiwix/search?pattern=&latitude=1 HTTP/1.1\r\n", request_line
assert_equal "200", response.code
assert_equal "hi", response.body
end
def test_proxy_returns_nil_when_nothing_is_listening
assert_nil Maptool::Kiwix.proxy("http://127.0.0.1:1", "/kiwix/search", "", open_timeout: 1)
end
end