Update app.js
Browse files
app.js
CHANGED
|
@@ -23,6 +23,17 @@ app.use(express.static(path.join(__dirname, 'public')));
|
|
| 23 |
// ββ Session store βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 24 |
const sessions = new Set();
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
// ββ ANSI stripper βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 27 |
function stripAnsi(str) {
|
| 28 |
// eslint-disable-next-line no-control-regex
|
|
@@ -340,7 +351,8 @@ app.get('/api/shellular/qr-data', requireAuth, (_req, res) => {
|
|
| 340 |
// ββ Start ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 341 |
app.listen(PORT, '0.0.0.0', () => {
|
| 342 |
console.log(`Shellular Web UI β http://0.0.0.0:${PORT}`);
|
| 343 |
-
startSyncPy();
|
|
|
|
| 344 |
});
|
| 345 |
|
| 346 |
// ββ Graceful shutdown ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 23 |
// ββ Session store βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 24 |
const sessions = new Set();
|
| 25 |
|
| 26 |
+
// Persistent auto-token derived from SECRET_KEY β survives restarts on the
|
| 27 |
+
// client side (stored in sessionStorage) and is always valid server-side.
|
| 28 |
+
const AUTO_TOKEN = crypto.createHash('sha256').update(`auto:${SECRET_KEY}`).digest('hex');
|
| 29 |
+
sessions.add(AUTO_TOKEN);
|
| 30 |
+
|
| 31 |
+
// Unauthenticated endpoint β lets the frontend self-authenticate after a
|
| 32 |
+
// container restart without the user having to type the key again.
|
| 33 |
+
app.get('/api/auto-token', (_req, res) => {
|
| 34 |
+
res.json({ token: AUTO_TOKEN });
|
| 35 |
+
});
|
| 36 |
+
|
| 37 |
// ββ ANSI stripper βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 38 |
function stripAnsi(str) {
|
| 39 |
// eslint-disable-next-line no-control-regex
|
|
|
|
| 351 |
// ββ Start ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 352 |
app.listen(PORT, '0.0.0.0', () => {
|
| 353 |
console.log(`Shellular Web UI β http://0.0.0.0:${PORT}`);
|
| 354 |
+
startSyncPy(); // π Launch sync.py on server start
|
| 355 |
+
startShellular(); // π Auto-start shellular on boot so QR is ready immediately
|
| 356 |
});
|
| 357 |
|
| 358 |
// ββ Graceful shutdown ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|