-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (28 loc) · 994 Bytes
/
index.js
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
const express = require('express');
const mongoose = require('mongoose');
const { processTransaction } = require('./controllers/transactionController');
const app = express();
const PORT = process.env.PORT || 3000;
app.use(express.json());
mongoose.connect('mongodb+srv://sindhu:[email protected]/?retryWrites=true&w=majority&appName=Cluster0', {
useNewUrlParser: true,
useUnifiedTopology: true,
}).then(() => {
console.log('Database connected');
}).catch(err => {
console.error('Database connection error', err);
});
// Endpoint to initiate a transaction
app.post('/transaction', async (req, res) => {
const { instanceId, bonusId, player } = req.body;
try {
await processTransaction(instanceId, bonusId, player);
res.status(200).send('Transaction processed successfully');
} catch (error) {
res.status(500).send('Transaction failed');
}
});
// Start the server
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});