This commit is contained in:
2024-02-20 17:15:27 +08:00
committed by huty
parent 6706e1a633
commit 34158042ad
1529 changed files with 177765 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: todo-api
labels:
kiamol: ch21
spec:
rules:
- host: api.todo.kiamol.local
http:
paths:
- path: /todos
backend:
serviceName: todo-api
servicePort: 8080
# this spec is equivalent to running
# kubeless trigger http create todo-api --function-name todo-api --path todos --hostname api.todo.kiamol.local
# but that fails with Kubeless 1.0.7 running on Kubernetes 1.18 - see
# https://github.com/kubeless/kubeless/issues/1130

View File

@@ -0,0 +1,11 @@
{
"name": "todo-api",
"version": "0.1.0",
"main": "server.js",
"author": "kiamol",
"dependencies": {
"nats" : "1.4.9",
"uuid" : "8.2.0"
}
}

View File

@@ -0,0 +1,21 @@
const NATS = require('nats')
const nc = NATS.connect({url: 'nats://message-queue:4222', json: true})
const { v4: uuidv4 } = require('uuid');
function handler(event, context) {
console.log('** todo-api handler called');
var newItemEvent = {
Subject: "events.todo.newitem",
Item: {
Item: event.data,
DateAdded: new Date().toISOString()
},
CorrelationId: uuidv4()
}
nc.publish('events.todo.newitem', newItemEvent)
console.log(`** New item published, event ID: ${newItemEvent.CorrelationId}`);
}
module.exports = { handler }