generated from arabold/serverless-react-boilerplate
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.ts
27 lines (26 loc) · 927 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
import "source-map-support/register";
import { Context, APIGatewayEvent, APIGatewayProxyResultV2 } from "aws-lambda";
export const serve = async (event: APIGatewayEvent, _context: Context): Promise<APIGatewayProxyResultV2> => {
try {
// We use asynchronous import here so we can better catch server-side errors during development
const render = (await import("./src/server/render")).default;
return {
statusCode: 200,
headers: {
"Content-Type": "text/html",
},
body: await render(event),
};
} catch (error) {
// Custom error handling for server-side errors
// TODO: Prettify the output, include the callstack, e.g. by using `youch` to generate beautiful error pages
console.error(error);
return {
statusCode: 500,
headers: {
"Content-Type": "text/html",
},
body: `<html><body>${error.toString()}</body></html>`,
};
}
};