Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/angry-pots-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/sandbox": patch
---

fix baseUrl for stub and stub forwarding
2 changes: 1 addition & 1 deletion packages/sandbox/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export class HttpClient {
let response: Response;

if (this.options.stub) {
response = await this.options.stub.containerFetch(path, options, this.options.port);
response = await this.options.stub.containerFetch(this.baseUrl + path, options, this.options.port);
} else {
response = await fetch(this.baseUrl + path, options);
}
Expand Down
39 changes: 22 additions & 17 deletions packages/sandbox/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,29 @@ export function getSandbox(ns: DurableObjectNamespace<Sandbox>, id: string) {
export class Sandbox<Env = unknown> extends Container<Env> {
defaultPort = 3000; // The default port for the container to listen on
sleepAfter = "3m"; // Sleep the sandbox if no requests are made in this timeframe
client: HttpClient;

client: HttpClient = new HttpClient({
onCommandComplete: (success, exitCode, stdout, stderr, command, args) => {
console.log(
`[Container] Command completed: ${command}, Success: ${success}, Exit code: ${exitCode}`
);
},
onCommandStart: (command, args) => {
console.log(`[Container] Command started: ${command} ${args.join(" ")}`);
},
onError: (error, command, args) => {
console.error(`[Container] Command error: ${error}`);
},
onOutput: (stream, data, command) => {
console.log(`[Container] [${stream}] ${data}`);
},
port: this.defaultPort,
});
constructor(ctx: DurableObjectState, env: Env) {
super(ctx, env);
this.client = new HttpClient({
onCommandComplete: (success, exitCode, stdout, stderr, command, args) => {
console.log(
`[Container] Command completed: ${command}, Success: ${success}, Exit code: ${exitCode}`
);
},
onCommandStart: (command, args) => {
console.log(`[Container] Command started: ${command} ${args.join(" ")}`);
},
onError: (error, command, args) => {
console.error(`[Container] Command error: ${error}`);
},
onOutput: (stream, data, command) => {
console.log(`[Container] [${stream}] ${data}`);
},
port: this.defaultPort,
stub: this,
});
}

envVars = {
MESSAGE: "I was passed in via the Sandbox class!",
Expand Down