forked from MyZubster-Ecosystem/myzubster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js.backup
More file actions
132 lines (120 loc) · 3.64 KB
/
Copy pathserver.js.backup
File metadata and controls
132 lines (120 loc) · 3.64 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const helmet = require('helmet');
const compression = require('compression');
const mongoose = require('mongoose');
const app = express();
const PORT = process.env.PORT || 10000;
// Middleware
app.use(helmet());
app.use(cors({
origin: process.env.CORS_ORIGIN || '*',
credentials: true
}));
app.use(compression());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Connessione a MongoDB
mongoose.connect(process.env.MONGODB_URI)
.then(() => console.log('✅ MongoDB connected'))
.catch(err => console.error('❌ MongoDB connection error:', err));
// Route
app.use('/api/auth', require('./src/routes/authRoutes'));
app.use('/api/animals', require('./src/routes/animalRoutes'));
app.use('/api/plants', require('./src/routes/plantRoutes'));
app.use('/api/bounties', require('./src/routes/bountyRoutes'));
app.use('/api/bounty-system', require('./src/routes/bountySystemRoutes'));
// Health check
app.get('/api/health', (req, res) => {
res.json({
status: 'ok',
timestamp: new Date().toISOString(),
uptime: process.uptime(),
mongodb: mongoose.connection.readyState === 1 ? 'connected' : 'disconnected'
});
});
// Info endpoint
app.get('/api/info', (req, res) => {
res.json({
name: 'MyZubster Gateway',
version: '1.0.0',
description: 'Monero Payment Gateway & Animal Registry',
features: {
payments: process.env.ENABLE_PAYMENTS === 'true',
animals: process.env.ENABLE_ANIMAL_REGISTRY === 'true',
plants: process.env.ENABLE_PLANT_REGISTRY === 'true',
bounty: process.env.ENABLE_BOUNTY_PROGRAM === 'true'
},
monero_wallet: process.env.MONERO_MAIN_WALLET_ADDRESS
});
});
// Root endpoint
app.get('/', (req, res) => {
res.json({
name: 'MyZubster Gateway',
version: '1.0.0',
status: 'running',
endpoints: {
health: '/api/health',
info: '/api/info',
auth: {
register: '/api/auth/register',
login: '/api/auth/login',
profile: '/api/auth/profile'
},
animals: {
list: '/api/animals',
register: '/api/animals/register',
detail: '/api/animals/:id'
},
plants: {
list: '/api/plants',
register: '/api/plants/register',
detail: '/api/plants/:id'
},
bounties: {
list: '/api/bounties',
create: '/api/bounties/create',
claim: '/api/bounties/:id/claim',
stats: '/api/bounties/stats'
}
}
});
});
// 404 handler
app.use((req, res) => {
res.status(404).json({
success: false,
error: 'Not Found',
message: `Endpoint ${req.method} ${req.path} does not exist`
});
});
// Error handler
app.use((err, req, res, next) => {
console.error('Error:', err);
res.status(500).json({
success: false,
error: 'Internal Server Error',
message: err.message
});
});
// Start server
const server = app.listen(PORT, '0.0.0.0', () => {
console.log(`🚀 MyZubster Gateway is running on port ${PORT}`);
console.log(`📊 Health check: http://localhost:${PORT}/api/health`);
console.log(`📋 Info: http://localhost:${PORT}/api/info`);
console.log(`🔐 Auth: http://localhost:${PORT}/api/auth/register`);
console.log(`🐾 Animals: http://localhost:${PORT}/api/animals`);
console.log(`🌿 Plants: http://localhost:${PORT}/api/plants`);
console.log(`🏆 Bounties: http://localhost:${PORT}/api/bounties`);
});
// Graceful shutdown
process.on('SIGTERM', () => {
console.log('📡 SIGTERM received, closing server...');
server.close(() => {
console.log('✅ Server closed');
process.exit(0);
});
});
module.exports = app;