Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
14 changes: 14 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Database Configuration
DATABASE_URL=postgresql://username:password@localhost:5432/vesting_vault
DB_HOST=localhost
DB_PORT=5432
DB_NAME=vesting_vault
DB_USER=username
DB_PASSWORD=password

# Stellar Configuration
STELLAR_RPC_URL=https://horizon-testnet.stellar.org
STELLAR_NETWORK=testnet

# Server Configuration
PORT=3000
61 changes: 60 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,67 @@
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 = 3000;
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());
Expand All @@ -17,3 +75,4 @@ app.get('/', (req, res) => {
});
});

app.listen(port, () => console.log(`Vesting API running on port ${port}`));
16 changes: 16 additions & 0 deletions node_modules/.bin/sha.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/sha.js.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions node_modules/.bin/sha.js.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading