Repository navigation
Expand file tree
/
Copy pathtest-api-server.mjs
More file actions
64 lines (54 loc) · 1.71 KB
/
Copy pathtest-api-server.mjs
File metadata and controls
64 lines (54 loc) · 1.71 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import express from 'express';
const app = express();
app.use(express.json());
// Enable CORS for all routes
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Authorization, Content-Type');
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
if (req.method === 'OPTIONS') {
return res.sendStatus(200);
}
next();
});
// Mock /api/upload/process endpoint
app.post('/api/upload/process', async (req, res) => {
const { filePath, fileName } = req.body;
// Check authorization header
const authHeader = req.headers.authorization;
if (!authHeader || !authHeader.startsWith('Bearer ')) {
return res.status(401).json({ error: 'Unauthorized' });
}
// Simulate processing
const bookId = 'book_' + Date.now();
const chaptersCount = Math.floor(Math.random() * 10) + 5;
console.log(`Processing EPUB: ${fileName} at ${filePath}`);
console.log(`Generated book ID: ${bookId} with ${chaptersCount} chapters`);
// Return success response
res.status(200).json({
success: true,
book: {
id: bookId,
title: fileName.replace('.epub', ''),
author: 'Test Author',
chaptersCount: chaptersCount,
processingTime: 1234
},
chaptersCount: chaptersCount,
stats: {
fileSize: 1048576,
processingTime: 1234,
memoryUsed: 50000000,
wordCount: 25000
}
});
});
// Health check endpoint
app.get('/health', (req, res) => {
res.json({ status: 'ok', server: 'test-api' });
});
const PORT = 3001;
app.listen(PORT, () => {
console.log(`Test API server running on http://localhost:${PORT}`);
console.log(`Ready to receive requests at /api/upload/process`);
});