I believe HTTP.binary()
or HTTP.structured()
should be used to transform event to headers and body.
const responseEventMessage = new CloudEvent({
...receivedEvent,
source: '/',
type: 'event:response'
});
// const message = HTTP.binary(responseEventMessage)
const message = HTTP.structured(responseEventMessage)
res.set(message.headers)
res.send(message.body)
Edit:
It might be required to set up body-parser.
const bodyParser = require('body-parser')
app.post("/", bodyParser.json(), (req, res) => {})
Also it's better to use cloneWith()
instead of spreading.
const responseEventMessage = receivedEvent.cloneWith({
source: '/',
type: 'event:response'
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…