Skip to content

Commit 9eba9a6

Browse files
committed
fix: use protocol-aware WebSocket URL for viewLog page
Construct the WebSocket URL dynamically based on the request protocol and host, so it uses wss:// when served over HTTPS. Enable trust proxy so Express respects X-Forwarded-Proto behind a reverse proxy. Pin socklog to v0.2.3 for crypto.randomUUID fix.
1 parent 374abfc commit 9eba9a6

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ async function initializeDayjs() {
3838

3939
app = express();
4040

41+
app.set('trust proxy', true);
42+
4143
app.use(morgan('[:mydate] :method :url :status :res[content-length] - :remote-addr - :response-time ms'));
4244

4345
app.use(cors());

controllers/view-log.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ const express = require('express'),
22
router = new express.Router();
33

44
router.get('/', function(req, res) {
5+
const wsProtocol = req.protocol === 'https' ? 'wss' : 'ws';
6+
const wsUrl = `${wsProtocol}://${req.get('host')}/wsLog`;
57
res.render('view-log', {
6-
host: req.app.locals.host,
7-
port: req.app.locals.port
8+
wsUrl
89
});
910
});
1011

views/view-log.handlebars

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<p>Real-time events on this rssCloud server.</p>
1212

1313
<script type="module">
14-
import 'https://esm.sh/@andrewshell/socklog'
14+
import 'https://esm.sh/@andrewshell/socklog@0.2.3'
1515
1616
const viewer = document.getElementById('viewer')
1717
const controls = document.getElementById('controls')
@@ -22,7 +22,7 @@
2222

2323
<div class="log-panel">
2424
<socklog-controls id="controls"></socklog-controls>
25-
<socklog-viewer id="viewer" url="ws://{{host}}:{{port}}/wsLog"></socklog-viewer>
25+
<socklog-viewer id="viewer" url="{{wsUrl}}"></socklog-viewer>
2626
</div>
2727

2828
<p class="mt-20">

0 commit comments

Comments
 (0)