diff --git a/src/index.mjs b/src/index.mjs
index 970015e..b9e024d 100644
--- a/src/index.mjs
+++ b/src/index.mjs
@@ -331,6 +331,15 @@ function buildGatePage(req) {
'
502: Bad Gateway',
`${reqHost} | 502: Bad gateway`
);
+ // Inject Onion-Location meta tag into for Tor Browser compatibility
+ if (cfg.websrv?.enable_tor_hs !== false && cfg.main?.onion && req && req.headers && !req.headers['host']?.endsWith('.onion')) {
+ const p = req.url?.pathname || '/';
+ const s = req.url?.search || '';
+ const onionHost = cfg.main.onion.replace(/\/+$/, '');
+ const onionUrl = `${onionHost}${p}${s}`;
+ html = html.replace('', `\n`);
+ }
+
html = html.replace('', gateLoginInjection + '\n');
return html;
}
@@ -1325,6 +1334,8 @@ process.on('uncaughtException', err => {
show_mime_picker: cfg.websrv.show_mime_picker !== false,
private_society: cfg.websrv.private_society || false,
private_society_gate: cfg.websrv.private_society_gate || '',
+ onion: cfg.main.onion || '',
+ enable_tor_hs: cfg.websrv.enable_tor_hs !== false,
show_content_warning: cfg.websrv.show_content_warning !== false,
web_url_upload: !!cfg.websrv.web_url_upload,
enable_youtube_upload: cfg.websrv.enable_youtube_upload !== false,
diff --git a/views/snippets/header.html b/views/snippets/header.html
index 227cc98..bb2e3e7 100644
--- a/views/snippets/header.html
+++ b/views/snippets/header.html
@@ -2,6 +2,7 @@
+ @if(enable_tor_hs && onion)@endif
@if(typeof page_meta !== 'undefined' && page_meta.title){{ domain }} - {{ page_meta.title }}@elseif(typeof item !== 'undefined'){{ domain }} - {{ item.id }}@else{{ domain }}@endif