@cloudflare/sandbox 0.0.0-c5bd973 → 0.0.0-cbb7fcd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/client.ts +1 -1
- package/src/index.ts +22 -17
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -212,7 +212,7 @@ export class HttpClient {
|
|
|
212
212
|
let response: Response;
|
|
213
213
|
|
|
214
214
|
if (this.options.stub) {
|
|
215
|
-
response = await this.options.stub.containerFetch(path, options, this.options.port);
|
|
215
|
+
response = await this.options.stub.containerFetch(this.baseUrl + path, options, this.options.port);
|
|
216
216
|
} else {
|
|
217
217
|
response = await fetch(this.baseUrl + path, options);
|
|
218
218
|
}
|
package/src/index.ts
CHANGED
|
@@ -8,24 +8,29 @@ export function getSandbox(ns: DurableObjectNamespace<Sandbox>, id: string) {
|
|
|
8
8
|
export class Sandbox<Env = unknown> extends Container<Env> {
|
|
9
9
|
defaultPort = 3000; // The default port for the container to listen on
|
|
10
10
|
sleepAfter = "3m"; // Sleep the sandbox if no requests are made in this timeframe
|
|
11
|
+
client: HttpClient;
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
13
|
+
constructor(ctx: DurableObjectState, env: Env) {
|
|
14
|
+
super(ctx, env);
|
|
15
|
+
this.client = new HttpClient({
|
|
16
|
+
onCommandComplete: (success, exitCode, stdout, stderr, command, args) => {
|
|
17
|
+
console.log(
|
|
18
|
+
`[Container] Command completed: ${command}, Success: ${success}, Exit code: ${exitCode}`
|
|
19
|
+
);
|
|
20
|
+
},
|
|
21
|
+
onCommandStart: (command, args) => {
|
|
22
|
+
console.log(`[Container] Command started: ${command} ${args.join(" ")}`);
|
|
23
|
+
},
|
|
24
|
+
onError: (error, command, args) => {
|
|
25
|
+
console.error(`[Container] Command error: ${error}`);
|
|
26
|
+
},
|
|
27
|
+
onOutput: (stream, data, command) => {
|
|
28
|
+
console.log(`[Container] [${stream}] ${data}`);
|
|
29
|
+
},
|
|
30
|
+
port: this.defaultPort,
|
|
31
|
+
stub: this,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
29
34
|
|
|
30
35
|
envVars = {
|
|
31
36
|
MESSAGE: "I was passed in via the Sandbox class!",
|