(event: any)
| 147 | }; |
| 148 | |
| 149 | export 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 | }; |
nothing calls this directly
no test coverage detected