howto

Receiving CloudEvents with NextJS

One file to rule them all

tags
nextjs
knative
cloudevents

Need to receive cloudevents from your NextJS app? Me too! You need next-runtime.

Install

1
  npm i next-runtime cloudevents

In pages/indes.ts

And then:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
  import { handle, json } from 'next-runtime';
  import { HTTP } from 'cloudevents';

  export const getServerSideProps = handle({
      async post({ req }) {
          console.log( req.body )
          console.log( req.headers )
        
          const receivedEvent = HTTP.toEvent({headers: req.headers, body: req.body })
          console.log( receivedEvent )
          return json({ message: 'Thanks for your submission!' });
      },
      async get() {
          return json( {message:"ok"} )
      }
  }))

Took me a while to sort out, but it wasn't so hard. Thanks meijer_s!

Previously

howto

Setting up knative eventing

lets send some messages

tags
knative
kubernetes
eventing

Next

howto

Setting up digital ocean spaces to upload

Gotta work on my upload scrips

tags
aws
s3
ruby
node
golang
deno
digitalocean