-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-server.js
More file actions
99 lines (92 loc) · 2.16 KB
/
Copy pathdev-server.js
File metadata and controls
99 lines (92 loc) · 2.16 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// dev-server.js - Local development server for API functions
const express = require('express');
const cors = require('cors');
const path = require('path');
const app = express();
const PORT = 3001;
// Middleware
app.use(cors());
app.use(express.json());
// Simple health check endpoint
app.get('/api/health', (req, res) => {
res.json({
success: true,
status: 'healthy',
timestamp: new Date().toISOString(),
message: 'Development API server is running'
});
});
// Cost calculation endpoint (mock for now)
app.get('/api/test/cost-calculation', (req, res) => {
res.json({
success: true,
data: [
{
model: 'gpt-3.5-turbo',
tokens: {
prompt: 1000,
completion: 500
},
cost: {
prompt: 0.0015,
completion: 0.002,
total: 0.0035
}
},
{
model: 'gpt-4',
tokens: {
prompt: 1000,
completion: 500
},
cost: {
prompt: 0.03,
completion: 0.06,
total: 0.09
}
},
{
model: 'gpt-4-turbo',
tokens: {
prompt: 1000,
completion: 500
},
cost: {
prompt: 0.01,
completion: 0.03,
total: 0.04
}
}
]
});
});
// OpenAI test endpoint (mock for now)
app.post('/api/test/openai', (req, res) => {
const { message } = req.body;
res.json({
success: true,
data: {
response: `Echo: ${message}`,
usage: {
prompt_tokens: 10,
completion_tokens: 5,
total_tokens: 15
},
cost: 0.0001
}
});
});
// Catch-all for other API routes (return mock success)
app.all('/api/*', (req, res) => {
console.log(`📡 Mock API call: ${req.method} ${req.path}`);
res.json({
success: true,
message: `Mock response for ${req.method} ${req.path}`,
data: {}
});
});
app.listen(PORT, () => {
console.log(`🚀 Development API server running on http://localhost:${PORT}`);
console.log(`📡 Frontend should connect to http://localhost:${PORT}/api/*`);
console.log(`🔧 This is a simplified mock server for local development`);
});