@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/sandbox",
3
- "version": "0.0.0-c5bd973",
3
+ "version": "0.0.0-cbb7fcd",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cloudflare/sandbox-sdk"
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
- client: HttpClient = new HttpClient({
13
- onCommandComplete: (success, exitCode, stdout, stderr, command, args) => {
14
- console.log(
15
- `[Container] Command completed: ${command}, Success: ${success}, Exit code: ${exitCode}`
16
- );
17
- },
18
- onCommandStart: (command, args) => {
19
- console.log(`[Container] Command started: ${command} ${args.join(" ")}`);
20
- },
21
- onError: (error, command, args) => {
22
- console.error(`[Container] Command error: ${error}`);
23
- },
24
- onOutput: (stream, data, command) => {
25
- console.log(`[Container] [${stream}] ${data}`);
26
- },
27
- port: this.defaultPort,
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!",