Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
78 lines (67 loc) · 1.88 KB
/
Copy pathindex.js
File metadata and controls
78 lines (67 loc) · 1.88 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
const express = require('express');
const cors = require('cors');
require('dotenv').config();
const { Client } = require('pg');
const { Server } = require('stellar-sdk');
const app = express();
const port = process.env.PORT || 3000;
app.use(cors());
// Health check endpoint
app.get('/health', async (req, res) => {
const health = {
status: 'ok',
timestamp: new Date().toISOString(),
services: {
database: 'unknown',
stellar: 'unknown'
}
};
let allHealthy = true;
// Check database connection
try {
const client = new Client({
connectionString: process.env.DATABASE_URL || {
host: process.env.DB_HOST,
port: process.env.DB_PORT,
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD
}
});
await client.connect();
await client.query('SELECT 1');
await client.end();
health.services.database = 'healthy';
} catch (error) {
health.services.database = 'unhealthy';
health.database_error = error.message;
allHealthy = false;
}
// Check Stellar RPC connection
try {
const stellarServer = new Server(process.env.STELLAR_RPC_URL || 'https://horizon-testnet.stellar.org');
await stellarServer.root();
health.services.stellar = 'healthy';
} catch (error) {
health.services.stellar = 'unhealthy';
health.stellar_error = error.message;
allHealthy = false;
}
if (allHealthy) {
res.status(200).json(health);
} else {
health.status = 'degraded';
res.status(503).json(health);
}
});
// Middleware
app.use(cors());
app.use(express.json());
app.get('/', (req, res) => {
res.json({
project: 'Vesting Vault',
status: 'Tracking Locked Tokens',
contract: 'CD5QF6KBAURVUNZR2EVBJISWSEYGDGEEYVH2XYJJADKT7KFOXTTIXLHU'
});
});
app.listen(port, () => console.log(`Vesting API running on port ${port}`));