generated from mats16/codespaces-cdk-template
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from supabase-community/fix-cdn
feat: Add Smart CDN Caching
- Loading branch information
Showing
14 changed files
with
468 additions
and
141 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Logger } from '@aws-lambda-powertools/logger'; | ||
import { Tracer } from '@aws-lambda-powertools/tracer'; | ||
import { SQSClient, SendMessageCommand } from '@aws-sdk/client-sqs'; | ||
import { Handler } from 'aws-lambda'; | ||
import { Hono } from 'hono'; | ||
import { handle } from 'hono/aws-lambda'; | ||
import { bearerAuth } from 'hono/bearer-auth'; | ||
import { WebhookEvent } from './types'; | ||
|
||
const region = process.env.AWS_REGION; | ||
const queueUrl = process.env.QUEUE_URL; | ||
const token = process.env.API_KEY!; | ||
const eventList = process.env.EVENT_LIST!.split(','); | ||
|
||
const logger = new Logger(); | ||
const tracer = new Tracer(); | ||
const sqs = tracer.captureAWSv3Client(new SQSClient({ region })); | ||
|
||
/** | ||
* Send message to SQS | ||
* @param message webhook event | ||
* @returns void | ||
*/ | ||
const enqueue = async (message: object) => { | ||
const cmd = new SendMessageCommand({ | ||
QueueUrl: queueUrl, | ||
MessageBody: JSON.stringify(message), | ||
}); | ||
await sqs.send(cmd); | ||
}; | ||
|
||
/** Hono app */ | ||
const app = new Hono(); | ||
|
||
/** Webhook endpoint */ | ||
app.post('/', bearerAuth({ token }), async (c) => { | ||
const body: WebhookEvent = await c.req.json(); | ||
console.log(JSON.stringify(body)); | ||
|
||
if (eventList.includes(body.event.type)) { | ||
await enqueue(body); | ||
} | ||
return c.text('Accepted', 202); | ||
}); | ||
|
||
/** Lambda handler */ | ||
export const handler = handle(app) as Handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.