From 8801903d01e0f0464b8202516b5d8d038183c88d Mon Sep 17 00:00:00 2001 From: Dmitry Verkhoturov Date: Tue, 18 Aug 2026 21:55:44 +0100 Subject: [PATCH] Derive host from the page URL on self-served pages Previously the pages Remark42 serves from /web/ carried a build-time host. The `{% REMARK_URL %}` placeholder is substituted during the image and release-asset builds, both of which write `http://127.0.0.1:8080`. Docker rewrites it again at container start from REMARK_URL, but a release binary has no equivalent step, so it serves demo, counter, last-comments and deleteme pages pointing at the visitor's own loopback address. `counter.ejs` additionally had that address hardcoded in two "note" links, which no substitution touched. These pages are served by Remark42 itself, so the host is whatever origin and path prefix delivered them. Deriving it from `location` is correct at the root and under a path prefix alike, and needs no build-time value. Sibling links are now relative for the same reason. `site_id` is left as a literal so the startup substitution in docker-init.sh keeps matching it. Reported by @andreas-hempel. Resolves #1996. --- frontend/apps/remark42/templates/counter.ejs | 6 +++--- frontend/apps/remark42/templates/deleteme.ejs | 2 +- frontend/apps/remark42/templates/demo.ejs | 14 ++++++++++---- frontend/apps/remark42/templates/last-comments.ejs | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/frontend/apps/remark42/templates/counter.ejs b/frontend/apps/remark42/templates/counter.ejs index b0999d47..b3c8f829 100644 --- a/frontend/apps/remark42/templates/counter.ejs +++ b/frontend/apps/remark42/templates/counter.ejs @@ -21,13 +21,13 @@

First counter with url from data-attribute: - (note) + (note)

Second counter with url from global remark config: - (note) + (note)

If it can't get url from data-attribute or remark config, it will try to use window.location.href for it.

@@ -36,7 +36,7 @@ diff --git a/frontend/apps/remark42/templates/demo.ejs b/frontend/apps/remark42/templates/demo.ejs index 2c04a4ad..59dc468f 100644 --- a/frontend/apps/remark42/templates/demo.ejs +++ b/frontend/apps/remark42/templates/demo.ejs @@ -72,11 +72,11 @@

@@ -121,9 +121,15 @@ window.REMARK42.changeTheme('dark'); }); + var remarkBase = location.origin + location.pathname.replace(/\/[^/]*$/, '').replace(/\/web$/, ''); + + document.querySelector('.widget__link_page_last-comments').href = remarkBase + '/web/last-comments.html'; + document.querySelector('.widget__comments-frame').src = remarkBase + '/web/last-comments.html'; + document.querySelector('.widget__link_page_counter').href = remarkBase + '/web/counter.html'; + var remark_config = { site_id: 'remark', - host: '<%= htmlWebpackPlugin.options.REMARK_URL %>', + host: remarkBase, url: window.location.href, components: ['embed', 'counter'], // __colors__: { diff --git a/frontend/apps/remark42/templates/last-comments.ejs b/frontend/apps/remark42/templates/last-comments.ejs index 77240412..3bb1654d 100644 --- a/frontend/apps/remark42/templates/last-comments.ejs +++ b/frontend/apps/remark42/templates/last-comments.ejs @@ -26,7 +26,7 @@