(request: Request, env: Env)
| 135 | |
| 136 | export default { |
| 137 | async fetch(request: Request, env: Env): Promise<Response> { |
| 138 | const url = new URL(request.url); |
| 139 | |
| 140 | const fileMatch = url.pathname.match(/^\/c\/([^/]+)\/file\/(.+)$/); |
| 141 | if (fileMatch) { |
| 142 | const resolved = resolveMountPath(fileMatch[2]); |
| 143 | if (resolved === null) { |
| 144 | return errorJSON(new Error(`path must sit under ${MOUNT_ROOT}; got /${fileMatch[2]}`), 400); |
| 145 | } |
| 146 | return handleFile(request, env, fileMatch[1], resolved); |
| 147 | } |
| 148 | |
| 149 | const execMatch = url.pathname.match(/^\/c\/([^/]+)\/exec\/?$/); |
| 150 | if (execMatch) return handleExec(request, env, execMatch[1]); |
| 151 | |
| 152 | if (url.pathname === "/" || url.pathname === "") { |
| 153 | return new Response( |
| 154 | [ |
| 155 | "container example", |
| 156 | "", |
| 157 | ` PUT /c/<name>/file/workspace/<path> write file at ${MOUNT_ROOT}/<path>`, |
| 158 | ` GET /c/<name>/file/workspace/<path> read file at ${MOUNT_ROOT}/<path>`, |
| 159 | " POST /c/<name>/exec run a command (JSON result)", |
| 160 | |
| 161 | "", |
| 162 | ].join("\n"), |
| 163 | { headers: { "content-type": "text/plain" } }, |
| 164 | ); |
| 165 | } |
| 166 | |
| 167 | return new Response("not found", { status: 404 }); |
| 168 | }, |
| 169 | } satisfies ExportedHandler<Env>; |
| 170 | |
| 171 | async function handleFile( |
nothing calls this directly
no test coverage detected