-
Notifications
You must be signed in to change notification settings - Fork 1
/
handler.ts
29 lines (24 loc) · 834 Bytes
/
handler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { dbClient } from '@sharingan/database';
import { renderSnippetToHtml } from '@sharingan/embed';
import { APIGatewayProxyEvent, APIGatewayProxyResult, Handler } from 'aws-lambda';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const shiki = require('shiki');
export const main: Handler<APIGatewayProxyEvent, APIGatewayProxyResult> = async (event) => {
const snippetId = event.pathParameters['id'];
const snippet = await dbClient.snippet.findFirst({ where: { id: snippetId, visibility: 'public' } });
const content = await renderSnippetToHtml({
options: {
scriptUrl: process.env.EMBED_JS_URL,
styleUrl: process.env.EMBED_STYLE_URL,
},
shiki,
snippet,
});
return {
body: content,
headers: {
'Content-Type': 'text/html',
},
statusCode: 200,
};
};