-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
86 lines (77 loc) · 1.97 KB
/
Copy pathserver.js
File metadata and controls
86 lines (77 loc) · 1.97 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
const express = require('express');
const cors = require('cors');
const os = require('os');
const app = express();
const PORT = process.env.PORT || 3000;
// Middleware
app.use(cors());
app.use(express.json());
// Health check endpoint
app.get('/health', (req, res) => {
res.json({
status: 'ok',
message: 'Agent Workstation API is running',
timestamp: new Date().toISOString()
});
});
// API info endpoint
app.get('/api/info', (req, res) => {
res.json({
name: 'Agent Workstation API',
version: '1.0.0',
environment: process.env.NODE_ENV || 'production',
server: {
hostname: os.hostname(),
platform: os.platform(),
release: os.release(),
cpus: os.cpus().length,
totalmem: `${Math.round(os.totalmem() / 1024 / 1024)} MB`,
uptime: `${Math.round(os.uptime() / 60)} minutes`
}
});
});
// Sample data endpoint
app.get('/api/data', (req, res) => {
res.json({
message: 'Welcome to Agent Workstation API!',
data: [
{ id: 1, name: 'Feature A', status: 'active' },
{ id: 2, name: 'Feature B', status: 'pending' },
{ id: 3, name: 'Feature C', status: 'completed' }
],
timestamp: new Date().toISOString()
});
});
// Root endpoint
app.get('/', (req, res) => {
res.json({
message: 'Welcome to Agent Workstation API',
endpoints: {
health: '/health',
info: '/api/info',
data: '/api/data'
}
});
});
// 404 handler
app.use((req, res) => {
res.status(404).json({
error: 'Not Found',
message: 'The requested endpoint does not exist',
path: req.path
});
});
// Error handler
app.use((err, req, res, next) => {
console.error('Error:', err);
res.status(500).json({
error: 'Internal Server Error',
message: err.message
});
});
// Start server
app.listen(PORT, '0.0.0.0', () => {
console.log(`Server is running on port ${PORT}`);
console.log(`Health check: http://localhost:${PORT}/health`);
console.log(`API info: http://localhost:${PORT}/api/info`);
});