-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
72 lines (62 loc) · 1.79 KB
/
server.js
File metadata and controls
72 lines (62 loc) · 1.79 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
const express = require('express');
const cors = require('cors');
const helmet = require('helmet');
const morgan = require('morgan');
require('dotenv').config();
const userRoutes = require('./routes/userRoutes');
const app = express();
const PORT = process.env.PORT || 3001;
// Middleware
app.use(helmet()); // Security headers
app.use(cors()); // Enable CORS
app.use(morgan('combined')); // Logging
app.use(express.json()); // Parse JSON bodies
app.use(express.urlencoded({ extended: true })); // Parse URL-encoded bodies
// Health check endpoint
app.get('/health', (req, res) => {
res.status(200).json({
success: true,
message: 'Ceph RGW Admin Server is running',
timestamp: new Date().toISOString(),
environment: process.env.NODE_ENV
});
});
// API routes
app.use('/api/users', userRoutes);
// Root endpoint
app.get('/', (req, res) => {
res.json({
success: true,
message: 'Ceph RGW Admin Server',
version: '1.0.0',
endpoints: {
health: '/health',
users: '/api/users'
}
});
});
// 404 handler
app.use('*', (req, res) => {
res.status(404).json({
success: false,
message: 'Endpoint not found',
path: req.originalUrl
});
});
// Global error handler
app.use((error, req, res, next) => {
console.error('Global error handler:', error);
res.status(500).json({
success: false,
message: 'Internal server error',
error: process.env.NODE_ENV === 'development' ? error.message : 'Something went wrong'
});
});
// Start server
app.listen(PORT, () => {
console.log(`🚀 Ceph RGW Admin Server running on port ${PORT}`);
console.log(`📊 Environment: ${process.env.NODE_ENV}`);
console.log(`🔗 Health check: http://localhost:${PORT}/health`);
console.log(`👥 User API: http://localhost:${PORT}/api/users`);
});
module.exports = app;