Add files via upload
This commit is contained in:
43
src/index.js
Normal file
43
src/index.js
Normal file
@@ -0,0 +1,43 @@
|
||||
require('dotenv').config();
|
||||
const express = require('express');
|
||||
const path = require('path');
|
||||
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();
|
||||
|
||||
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')));
|
||||
|
||||
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 * * *'}`);
|
||||
});
|
||||
Reference in New Issue
Block a user