The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | // A Lambda Web Function origin. It echoes what reached it so the test can |
| 2 | // confirm CloudFront forwards the whole viewer request (method, query, |
| 3 | // body, the application's own Authorization header) while signing the |
| 4 | // origin request itself. |
| 5 | import * as http from "node:http"; |
| 6 | |
| 7 | const [host, port] = (process.env.AWS_LAMBDA_HTTP_ENDPOINT ?? "localhost:3000").split(":"); |
| 8 | |
| 9 | http |
| 10 | .createServer(async (req, res) => { |
| 11 | const url = new URL(req.url ?? "/", "http://localhost"); |
| 12 | let body: string | null = null; |
| 13 | if (req.method !== "GET" && req.method !== "HEAD") { |
| 14 | const chunks: Buffer[] = []; |
| 15 | for await (const chunk of req) chunks.push(chunk as Buffer); |
| 16 | body = Buffer.concat(chunks).toString("utf8"); |
| 17 | } |
| 18 | res.writeHead(200, { "content-type": "application/json" }); |
| 19 | res.end( |
| 20 | JSON.stringify({ |
| 21 | message: "hello through cloudfront", |
| 22 | method: req.method, |
| 23 | query: url.search, |
| 24 | body, |
| 25 | endpoint: req.headers["lambda-web-endpoint-name"] ?? null, |
| 26 | authorization: req.headers.authorization ?? null, |
| 27 | }), |
| 28 | ); |
| 29 | }) |
| 30 | .listen(Number(port), host); |