-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
43 lines (31 loc) · 942 Bytes
/
app.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
const express = require('express');
const app = express();
const PORT = 3000;
// Health check endpoint for readiness probe
app.get('/_ah/ready', (req, res) => {
res.sendStatus(200);
});
app.get('/_ah/live', (req, res) => {
res.sendStatus(200);
});
app.get('/', (req, res) => {
res.send('Hello World! Service version:01 Current time: ' + new Date().toISOString());
});
app.post('/pubsub', express.json(), (req, res) => {
const message = req.body.message;
log(`Received message ${message.data} with attributes ${JSON.stringify(message.attributes)}.`);
// Process the message here
res.sendStatus(200);
});
app.listen(PORT, () => {
log(`Server listening on port ${PORT}...`);
});
function log(message) {
const logEntry = {
timestamp: new Date().toISOString(),
component: "app.js",
severity: "INFO",
message: message
}
console.log(JSON.stringify(logEntry));
}