init commit,
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
# Writing functions using Oak Server Middleware
|
||||
|
||||
This example shows how you can write functions using Oak server middleware (https://oakserver.github.io/oak/)
|
||||
|
||||
## Run locally
|
||||
|
||||
```bash
|
||||
supabase functions serve --no-verify-jwt
|
||||
```
|
||||
|
||||
Use cURL or Postman to make a POST request to http://localhost:54321/functions/v1/oak-server/greet.
|
||||
|
||||
```
|
||||
curl --location --request POST 'http://localhost:54321/functions/v1/oak-server/greet' \
|
||||
--header 'Authorization: Bearer YOUR_TOKEN' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data-raw '{ "name": "John Doe" }'
|
||||
```
|
||||
|
||||
## Deploy
|
||||
|
||||
```bash
|
||||
supabase functions deploy oak-server --no-verify-jwt
|
||||
```
|
@@ -0,0 +1,25 @@
|
||||
import { Application, Router } from 'https://deno.land/x/oak@v11.1.0/mod.ts'
|
||||
|
||||
const router = new Router()
|
||||
router
|
||||
// Note: path should be prefixed with function name
|
||||
.get('/oak-server', (context) => {
|
||||
context.response.body = 'This is an example Oak server running on Edge Functions!'
|
||||
})
|
||||
.post('/oak-server/greet', async (context) => {
|
||||
// Note: request body will be streamed to the function as chunks, set limit to 0 to fully read it.
|
||||
const result = context.request.body({ type: 'json', limit: 0 })
|
||||
const body = await result.value
|
||||
const name = body.name || 'you'
|
||||
|
||||
context.response.body = { msg: `Hey ${name}!` }
|
||||
})
|
||||
.get('/oak-server/redirect', (context) => {
|
||||
context.response.redirect('https://www.example.com')
|
||||
})
|
||||
|
||||
const app = new Application()
|
||||
app.use(router.routes())
|
||||
app.use(router.allowedMethods())
|
||||
|
||||
await app.listen({ port: 8000 })
|
Reference in New Issue
Block a user