-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsimple-server.js
More file actions
63 lines (54 loc) · 1.34 KB
/
simple-server.js
File metadata and controls
63 lines (54 loc) · 1.34 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
import Fastify from 'fastify';
console.log('🚀 Starting Simple Code Mode Server...');
const fastify = Fastify({
logger: {
level: 'info',
transport: {
target: 'pino-pretty'
}
}
});
// Simple health endpoint
fastify.get('/health', async (request, reply) => {
return { status: 'healthy', timestamp: new Date().toISOString() };
});
// Simple execute endpoint
fastify.post('/execute', async (request, reply) => {
const { code } = request.body;
if (!code) {
return reply.code(400).send({ error: 'No code provided' });
}
try {
// Simple eval for testing - NOT SECURE FOR PRODUCTION
const result = eval(code);
return {
success: true,
result,
metrics: {
executionTime: 1,
memoryUsed: 1024,
apiCalls: 0
}
};
} catch (error) {
return {
success: false,
error: {
type: 'runtime',
message: error.message
}
};
}
});
// Start server
const start = async () => {
try {
await fastify.listen({ port: 3001, host: 'localhost' });
console.log('✅ Simple Code Mode Server running on http://localhost:3001');
console.log('📝 Try: curl -X POST http://localhost:3001/execute -H "Content-Type: application/json" -d \'{"code": "Math.sqrt(16)"}\'');
} catch (err) {
fastify.log.error(err);
process.exit(1);
}
};
start();