-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
63 lines (52 loc) · 1.51 KB
/
app.js
File metadata and controls
63 lines (52 loc) · 1.51 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
const express = require('express');
const helmet = require('helmet');
const path = require('path');
const app = express();
const PORT = process.env.PORT || 3000;
// Security middleware
app.use(helmet());
// Middleware
app.use(express.static('public'));
app.use(express.json());
// Routes
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
app.get('/health', (req, res) => {
res.status(200).json({
status: 'healthy',
timestamp: new Date().toISOString(),
version: process.env.npm_package_version || '1.0.0'
});
});
app.get('/api/info', (req, res) => {
res.json({
message: 'DevOps Portfolio Application',
environment: process.env.NODE_ENV || 'development',
version: process.env.npm_package_version || '1.0.0',
hostname: require('os').hostname()
});
});
// Error handling
app.use((req, res) => {
res.status(404).json({ error: 'Route not found' });
});
app.use((err, req, res, _next) => {
console.error(err.stack);
res.status(500).json({ error: 'Something went wrong!' });
});
// Only start server if this file is run directly
if (require.main === module) {
const server = app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
console.log(`Environment: ${process.env.NODE_ENV || 'development'}`);
});
// Graceful shutdown
process.on('SIGTERM', () => {
console.log('SIGTERM received, shutting down gracefully');
server.close(() => {
console.log('Process terminated');
});
});
}
module.exports = app;