Skip to content

Commit e1287b6

Browse files
committed
v3.5.2 - Added HTTPS/SSL self-signed support | Updated README
1 parent a869804 commit e1287b6

File tree

4 files changed

+81
-25
lines changed

4 files changed

+81
-25
lines changed

server/lynx.db-shm

0 Bytes
Binary file not shown.

server/package-lock.json

Lines changed: 48 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"jsonwebtoken": "^9.0.2",
2121
"multer": "^1.4.5-lts.1",
2222
"node-fetch": "^2.7.0",
23+
"selfsigned": "^2.4.1",
2324
"sqlite3": "^5.1.6",
2425
"zod": "^3.23.8"
2526
}

server/server.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import express from 'express';
2+
import https from 'https';
23
import cors from 'cors';
34
import { fileURLToPath } from 'url';
45
import { dirname, join } from 'path';
@@ -40,6 +41,8 @@ function safeJsonParse(jsonString, defaultValue = {}) {
4041

4142
const app = express();
4243
const PORT = process.env.PORT || 3001;
44+
const ENABLE_HTTPS = String(process.env.ENABLE_HTTPS || '').toLowerCase() === 'true' || process.env.ENABLE_HTTPS === '1';
45+
const SSL_PORT = Number.parseInt(process.env.SSL_PORT || '', 10) || 8443;
4346
const FRONTEND_URL = process.env.FRONTEND_URL || `http://localhost:${PORT}`;
4447
const COOKIE_SECRET = process.env.COOKIE_SECRET || 'dev-cookie-secret';
4548

@@ -1162,8 +1165,8 @@ app.get('*', spaLimiter, (req, res) => {
11621165
res.sendFile(join(__dirname, '../dist/index.html'));
11631166
});
11641167

1165-
app.listen(PORT, '0.0.0.0', () => {
1166-
console.log(`Server running on port ${PORT}`);
1168+
app.listen(PORT, '0.0.0.0', async () => {
1169+
console.log(`HTTP server running on port ${PORT}`);
11671170
console.log(`Frontend: http://localhost:${PORT}`);
11681171
console.log(`API: http://localhost:${PORT}/api`);
11691172
console.log('Rate limiting active:');
@@ -1172,4 +1175,31 @@ app.listen(PORT, '0.0.0.0', () => {
11721175
console.log('- Login attempts: 5 failed/10min per IP');
11731176
console.log('- Force reset: 2 requests/hour per IP');
11741177
console.log('Trust proxy:', app.get('trust proxy') ? 'Enabled' : 'Disabled');
1178+
1179+
if (ENABLE_HTTPS) {
1180+
try {
1181+
const mod = await import('selfsigned');
1182+
const selfsigned = mod.default || mod;
1183+
const attrs = [{ name: 'commonName', value: 'localhost' }];
1184+
const pems = selfsigned.generate(attrs, {
1185+
days: 7,
1186+
keySize: 2048,
1187+
algorithm: 'sha256'
1188+
});
1189+
1190+
const httpsServer = https.createServer({ key: pems.private, cert: pems.cert }, app);
1191+
httpsServer.listen(SSL_PORT, '0.0.0.0', () => {
1192+
console.log(`HTTPS server running on port ${SSL_PORT}`);
1193+
console.log('HTTPS: Enabled (self-signed certificate)');
1194+
});
1195+
httpsServer.on('error', (err) => {
1196+
console.error('HTTPS server error:', err?.message || err);
1197+
});
1198+
} catch (err) {
1199+
console.error('Failed to start HTTPS server (self-signed):', err?.message || err);
1200+
console.log('HTTPS: Disabled due to error');
1201+
}
1202+
} else {
1203+
console.log('HTTPS: Disabled');
1204+
}
11751205
});

0 commit comments

Comments
 (0)