Initial commit

This commit is contained in:
2021-08-01 17:19:21 -04:00
commit 48bdeeba33
36 changed files with 23143 additions and 0 deletions

1
blog/posts/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
node_modules/

37
blog/posts/index.js Normal file
View File

@@ -0,0 +1,37 @@
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const { randomBytes } = require('crypto');
const axios = require('axios');
const app = express();
app.use(bodyParser.json());
app.use(cors());
const posts = {};
app.get('/posts', (req, res) => {
res.send(posts);
});
app.post('/posts', async (req, res) => {
const id = randomBytes(4).toString('hex');
const { title } = req.body;
posts[id] = { id, title };
await axios.post('http://localhost:4005/events', {
type: 'PostCreated',
data: posts[id]
}).catch(error => console.log(error));
res.status(201).send(posts[id]);
});
app.post('/events', (req, res) => {
console.log('Received Event', req.body.type);
res.send({});
});
app.listen(4000, () => {
console.log('Listening on 4000');
});

1256
blog/posts/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

18
blog/posts/package.json Normal file
View File

@@ -0,0 +1,18 @@
{
"name": "posts",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.21.1",
"cors": "^2.8.5",
"express": "^4.17.1",
"nodemon": "^2.0.7"
}
}