mkdir netbet
cd netbet
npm init -y
npm install express body-parser
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const PORT = 3000;
app.use(bodyParser.json());
// Mock data for odds
const odds = {
'match1': { 'teamA': 1.5, 'teamB': 2.0 },
'match2': { 'teamC': 1.8, 'teamD': 2.2 }
};
// Endpoint to get odds for a match
app.get('/api/odds/:matchId', (req, res) => {
const matchId = req.params.matchId;
if (odds[matchId]) {
res.json(odds[matchId]);
} else {
res.status(404).send('Match not found');
}
});
// Endpoint to place a bet
app.post('/api/bet', (req, res) => {
const { matchId, team, amount } = req.body;
if (odds[matchId] && odds[matchId][team]) {
// Logic for placing the bet (e.g., save to database)
res.json({ message: 'Bet placed successfully', bet: { matchId, team, amount } });
} else {
res.status(400).send('Invalid match or team');
}
});
// Start the server
app.listen(PORT, () => {
console.log(`NetBet server running on port ${PORT}`);
});
Comments
Post a Comment