Repository navigation
Expand file tree
/
Copy pathserver.js
More file actions
96 lines (86 loc) · 2.47 KB
/
Copy pathserver.js
File metadata and controls
96 lines (86 loc) · 2.47 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
const express = require('express');
const app = express();
const port = process.env.PORT || 8080;
// Middleware
app.use(express.json());
// Health check endpoint
app.get('/health', (req, res) => {
res.status(200).json({
status: 'healthy',
timestamp: new Date().toISOString(),
version: process.env.npm_package_version || '1.0.0',
environment: process.env.NODE_ENV || 'development'
});
});
// Root endpoint
app.get('/', (req, res) => {
res.json({
message: '🚀 DevSecOps Sample Application',
description: 'A sample application demonstrating DevSecOps CI/CD pipeline with security scanning',
endpoints: {
health: '/health',
metrics: '/metrics',
info: '/info'
},
security: {
scanning: 'enabled',
tools: ['gitleaks', 'trivy', 'semgrep', 'checkov', 'hadolint'],
gates: 'enforced'
}
});
});
// Info endpoint
app.get('/info', (req, res) => {
res.json({
application: 'DevSecOps Sample App',
version: process.env.npm_package_version || '1.0.0',
build: process.env.BUILD_NUMBER || 'local',
commit: process.env.GIT_COMMIT || 'unknown',
environment: process.env.NODE_ENV || 'development',
uptime: process.uptime(),
memory: process.memoryUsage(),
platform: process.platform,
nodeVersion: process.version
});
});
// Metrics endpoint (basic)
app.get('/metrics', (req, res) => {
res.json({
uptime: process.uptime(),
memory: process.memoryUsage(),
cpu: process.cpuUsage(),
timestamp: new Date().toISOString()
});
});
// 404 handler
app.use('*', (req, res) => {
res.status(404).json({
error: 'Not Found',
message: 'The requested endpoint does not exist',
availableEndpoints: ['/', '/health', '/info', '/metrics']
});
});
// Error handler
app.use((err, req, res, next) => {
console.error('Error:', err);
res.status(500).json({
error: 'Internal Server Error',
message: 'Something went wrong!'
});
});
// Start server
app.listen(port, '0.0.0.0', () => {
console.log(`🚀 DevSecOps Sample App listening on port ${port}`);
console.log(`📊 Health check: http://localhost:${port}/health`);
console.log(`📋 Info: http://localhost:${port}/info`);
console.log(`📈 Metrics: http://localhost:${port}/metrics`);
});
// Graceful shutdown
process.on('SIGTERM', () => {
console.log('SIGTERM received, shutting down gracefully');
process.exit(0);
});
process.on('SIGINT', () => {
console.log('SIGINT received, shutting down gracefully');
process.exit(0);
});