-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
48 lines (40 loc) · 1.64 KB
/
Copy pathserver.js
File metadata and controls
48 lines (40 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require('dotenv').config();
const express = require('express');
const path = require('path');
const config = require('./config');
const imageSearch = require('./services/imageSearch');
// Init imageSearch with runtime config
imageSearch.init({
deepseekApiKey: config.runtimeConfig.deepseekApiKey,
pexelsApiKey: config.runtimeConfig.pexelsApiKey,
});
const app = express();
const PORT = process.env.PORT || 3000;
app.use(express.json());
app.use(express.static('public'));
app.use('/audio', express.static(config.AUDIO_DIR));
app.use('/video', express.static(config.VIDEO_DIR));
// Disable caching for API responses
app.use('/api', (req, res, next) => {
res.set('Cache-Control', 'no-store, no-cache, must-revalidate');
res.set('Pragma', 'no-cache');
next();
});
// Mount routes
app.use('/api', require('./routes/extract'));
app.use('/api/rewrite', require('./routes/rewrite'));
app.use('/api/tts', require('./routes/tts'));
app.use('/api/video', require('./routes/video'));
app.use('/api/templates', require('./routes/templates'));
app.use('/api/scorer', require('./routes/scorer'));
app.use('/api/history', require('./routes/history'));
app.use('/api/config', require('./routes/config'));
app.use('/api', require('./routes/cache'));
// Error handler — logs safe message only, never exposes paths or keys
app.use((err, req, res, next) => {
console.error(`Server error on ${req.method} ${req.path}:`, err.message || err);
res.status(500).json({ success: false, error: { code: 'UNKNOWN_ERROR', message: '服务器内部错误,请稍后重试' } });
});
app.listen(PORT, () => {
console.log(`Echo Editorial / 回声编辑部: http://localhost:${PORT}`);
});