2026-03-03 10:20:07 -06:00
|
|
|
const express = require('express');
|
|
|
|
|
const path = require('path');
|
2026-03-13 14:38:19 -05:00
|
|
|
const fs = require('fs');
|
2026-03-03 10:20:07 -06:00
|
|
|
const basicAuth = require('express-basic-auth');
|
|
|
|
|
const { initDb } = require('./db/sqlite');
|
|
|
|
|
const adminRoutes = require('./routes/admin');
|
|
|
|
|
const pushRoutes = require('./routes/push');
|
|
|
|
|
const { startScheduler } = require('./services/scheduler');
|
|
|
|
|
|
|
|
|
|
const app = express();
|
|
|
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
|
|
|
|
|
|
initDb();
|
|
|
|
|
|
2026-03-13 14:38:19 -05:00
|
|
|
// Ensure uploads directory exists
|
|
|
|
|
const uploadsDir = path.join(__dirname, '../public/uploads');
|
|
|
|
|
if (!fs.existsSync(uploadsDir)) {
|
|
|
|
|
fs.mkdirSync(uploadsDir, { recursive: true });
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-03 10:20:07 -06:00
|
|
|
const auth = basicAuth({
|
|
|
|
|
users: { [process.env.ADMIN_USERNAME || 'admin']: process.env.ADMIN_PASSWORD || 'changeme' },
|
|
|
|
|
challenge: true,
|
|
|
|
|
realm: 'Email Signature Manager'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.use(express.json());
|
|
|
|
|
app.use(express.static(path.join(__dirname, '../public')));
|
2026-03-13 14:38:19 -05:00
|
|
|
app.use('/uploads', express.static(uploadsDir));
|
2026-03-03 10:20:07 -06:00
|
|
|
|
|
|
|
|
app.use('/api/admin', auth, adminRoutes);
|
|
|
|
|
app.use('/api/push', auth, pushRoutes);
|
|
|
|
|
|
|
|
|
|
app.get('/dashboard', auth, (req, res) => {
|
|
|
|
|
res.sendFile(path.join(__dirname, '../public/dashboard.html'));
|
|
|
|
|
});
|
|
|
|
|
app.get('/editor', auth, (req, res) => {
|
|
|
|
|
res.sendFile(path.join(__dirname, '../public/editor.html'));
|
|
|
|
|
});
|
|
|
|
|
app.get('/', auth, (req, res) => {
|
|
|
|
|
res.redirect('/dashboard');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
startScheduler();
|
|
|
|
|
|
|
|
|
|
app.listen(PORT, () => {
|
|
|
|
|
console.log(`Email Signature Manager running on port ${PORT}`);
|
|
|
|
|
console.log(`Admin: ${process.env.ADMIN_USERNAME || 'admin'}`);
|
|
|
|
|
console.log(`Cron: ${process.env.CRON_SCHEDULE || '0 2 * * *'}`);
|
|
|
|
|
});
|