Files
microservices-course/blog/event-bus/index.js
2021-08-01 17:19:21 -04:00

31 lines
782 B
JavaScript

const express = require('express');
const bodyParser = require('body-parser');
const axios = require('axios');
const app = express();
app.use(bodyParser.json());
const events = [];
app.post('/events', (req, res) => {
const event = req.body;
events.push(event);
axios.post('http://localhost:4000/events', event).catch(error => console.log(error));
axios.post('http://localhost:4001/events', event).catch(error => console.log(error));
axios.post('http://localhost:4002/events', event).catch(error => console.log(error));
axios.post('http://localhost:4003/events', event).catch(error => console.log(error));
res.send({status: 'OK'});
});
app.get('/events', (req, res) => {
res.send(events);
});
app.listen(4005, () => {
console.log('Listening on 4005');
});