-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-api.js
More file actions
100 lines (92 loc) · 2.45 KB
/
test-api.js
File metadata and controls
100 lines (92 loc) · 2.45 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
100
const express = require('express');
const cors = require('cors');
const app = express();
const PORT = 8080;
// Middleware
app.use(cors());
app.use(express.json());
// Routes
app.get('/health', (req, res) => {
res.json({
status: 'healthy',
message: 'VPN API is running',
timestamp: new Date().toISOString()
});
});
app.get('/api/status', (req, res) => {
res.json({
wireguard: {
status: 'running',
peers: 0,
transfer_rx: 0,
transfer_tx: 0
},
system: {
cpu_percent: 25.5,
memory_percent: 50.0,
disk_percent: 30.0
}
});
});
app.get('/api/clients', (req, res) => {
res.json([
{
id: 1,
name: 'test-client',
public_key: 'test-public-key-12345',
ip_address: '10.0.0.2',
is_active: true,
bytes_received: 1024,
bytes_sent: 2048,
created_at: new Date().toISOString()
},
{
id: 2,
name: 'mobile-client',
public_key: 'test-public-key-67890',
ip_address: '10.0.0.3',
is_active: true,
bytes_received: 5120,
bytes_sent: 8192,
created_at: new Date().toISOString()
}
]);
});
app.post('/api/auth/login', (req, res) => {
const { username, password } = req.body;
if (username === 'admin' && password === 'admin123') {
res.json({
access_token: 'test-token-12345',
user: {
id: 1,
username: 'admin',
email: 'admin@vpn.local',
is_admin: true
}
});
} else {
res.status(401).json({
error: 'Invalid credentials'
});
}
});
app.get('/api/servers', (req, res) => {
res.json([
{
id: 1,
name: 'main-server',
endpoint: 'vpn.example.com',
port: 51820,
public_key: 'server-public-key-12345',
status: 'running',
connected_clients: 2
}
]);
});
// Start server
app.listen(PORT, () => {
console.log(`🚀 VPN Test API running on http://localhost:${PORT}`);
console.log(`📊 Health check: http://localhost:${PORT}/health`);
console.log(`👥 Clients: http://localhost:${PORT}/api/clients`);
console.log(`🔐 Login: POST http://localhost:${PORT}/api/auth/login`);
});