@@ -8,24 +8,29 @@ export function getSandbox(ns: DurableObjectNamespace<Sandbox>, id: string) {
88export class Sandbox < Env = unknown > extends Container < Env > {
99 defaultPort = 3000 ; // The default port for the container to listen on
1010 sleepAfter = "3m" ; // Sleep the sandbox if no requests are made in this timeframe
11+ client : HttpClient ;
1112
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+ }
2934
3035 envVars = {
3136 MESSAGE : "I was passed in via the Sandbox class!" ,
0 commit comments