forked from admin/zeropost-engine
612053b93d
- AI service with Anthropic claude-sonnet-4-6 - Bull queue for async generation jobs - Routes: /api/generate, /api/channels, /api/posts - PostgreSQL schema: users, channels, posts, generation_jobs - Supports: post, article, topics generation types
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
const express = require('express');
|
|
const config = require('./src/config');
|
|
const { migrate } = require('./src/config/db');
|
|
|
|
// Routes
|
|
const generateRoutes = require('./src/routes/generate');
|
|
const channelsRoutes = require('./src/routes/channels');
|
|
const postsRoutes = require('./src/routes/posts');
|
|
|
|
// Start queue worker
|
|
require('./src/workers/generation');
|
|
|
|
const app = express();
|
|
app.use(express.json());
|
|
|
|
// Simple internal auth middleware
|
|
app.use((req, res, next) => {
|
|
const secret = req.headers['x-internal-secret'];
|
|
if (secret !== config.internalSecret) {
|
|
return res.status(401).json({ error: 'Unauthorized' });
|
|
}
|
|
next();
|
|
});
|
|
|
|
app.use('/api/generate', generateRoutes);
|
|
app.use('/api/channels', channelsRoutes);
|
|
app.use('/api/posts', postsRoutes);
|
|
|
|
app.get('/health', (req, res) => {
|
|
res.json({ ok: true, service: 'zeropost-engine', time: new Date() });
|
|
});
|
|
|
|
const start = async () => {
|
|
await migrate();
|
|
app.listen(config.port, () => {
|
|
console.log(`[Engine] Running on port ${config.port}`);
|
|
});
|
|
};
|
|
|
|
start().catch(err => {
|
|
console.error('[Engine] Failed to start:', err);
|
|
process.exit(1);
|
|
});
|