MCPcopy Create free account
hub / github.com/awslabs/llrt / handler

Function handler

example/functions/src/ssr.ts:149–184  ·  view source on GitHub ↗
(event: any)

Source from the content-addressed store, hash-verified

147};
148
149export const handler = async (event: any) => {
150 const { method = "GET", path: eventPath = "/" } =
151 event?.requestContext?.http || {};
152
153 try {
154 const reqSegments: string[] = (eventPath as string)
155 .split("/")
156 .filter((x) => x)
157 .slice(1);
158 console.log({ reqSegments, eventPath, method });
159
160 if (reqSegments[0] === "api") {
161 return await apiResponse(reqSegments.slice(1), method, event.body);
162 }
163
164 if (method === "GET") {
165 if (reqSegments.length === 0) {
166 return await appResponse();
167 }
168 return await assetResponse(reqSegments.join("/"));
169 }
170 throw new HttpError(400, "Method not supported");
171 } catch (e) {
172 console.error(e);
173 if (e instanceof HttpError) {
174 return {
175 statusCode: e.status,
176 body: e.message,
177 };
178 }
179 return {
180 statusCode: 500,
181 body: "Internal server error",
182 };
183 }
184};

Callers

nothing calls this directly

Calls 7

apiResponseFunction · 0.85
appResponseFunction · 0.85
assetResponseFunction · 0.85
joinMethod · 0.80
logMethod · 0.65
errorMethod · 0.65
sliceMethod · 0.45

Tested by

no test coverage detected