-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (44 loc) · 1.02 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const express = require("express");
const bodyParser = require("body-parser");
const { randomBytes } = require("crypto");
const cors = require("cors");
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/create", async (req, res) => {
const id = randomBytes(4).toString("hex");
const { title } = req.body;
posts[id] = {
id,
title,
};
await axios.post("http://event-bus-srv:4005/events", {
type: "PostCreated",
data: {
id,
title,
},
});
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 port");
});
// kubectl rollout restart deployment posts-depl
// apiVersion: v1
// kind: Pod
// metadata:
// name: posts
// spec:
// containers:
// - name: posts
// image: hritikchokker/posts:0.0.1