@@ -4,6 +4,7 @@ import stream from 'stream'
44import express from 'express'
55
66const jwt = require ( 'express-jwt' )
7+ const asyncHandler = require ( 'express-async-handler' )
78
89import Environment , { ContainerStatus , Platform , SessionParameters } from './Environment'
910
@@ -135,7 +136,7 @@ function getJwtData (request: express.Request, response: express.Response, expec
135136}
136137
137138// Instantiate shell and set up data handlers
138- expressWs . app . ws ( '/shell' , async ( ws : any , req : express . Request ) => {
139+ expressWs . app . ws ( '/shell' , asyncHandler ( async ( ws : any , req : express . Request ) => {
139140 const environment = req . query . environment || DEFAULT_ENVIRONMENT
140141
141142 const jwtData = getJwtData ( req , ws , null )
@@ -172,10 +173,10 @@ expressWs.app.ws('/shell', async (ws: any, req: express.Request) => {
172173 } catch ( error ) {
173174 console . error ( error )
174175 }
175- } )
176+ } ) )
176177
177178// Instantiate shell and set up data handlers but connect to an existing container
178- expressWs . app . ws ( '/interact' , async ( ws : any , req : express . Request ) => {
179+ expressWs . app . ws ( '/interact' , asyncHandler ( async ( ws : any , req : express . Request ) => {
179180 const environment = req . query . environment || DEFAULT_ENVIRONMENT
180181 const containerId = req . query . containerId || ''
181182
@@ -215,9 +216,9 @@ expressWs.app.ws('/interact', async (ws: any, req: express.Request) => {
215216 } catch ( error ) {
216217 console . error ( error )
217218 }
218- } )
219+ } ) )
219220
220- expressWs . app . post ( '/start' , async ( req : express . Request , res : express . Response ) => {
221+ expressWs . app . post ( '/start' , asyncHandler ( async ( req : express . Request , res : express . Response ) => {
221222 const jwtData = getJwtData ( req , res )
222223
223224 if ( jwtData === null ) {
@@ -246,9 +247,9 @@ expressWs.app.post('/start', async (req: express.Request, res: express.Response)
246247 return res . json ( {
247248 containerId : containerId
248249 } )
249- } )
250+ } ) )
250251
251- expressWs . app . post ( '/execute' , async ( req : express . Request , res : express . Response ) => {
252+ expressWs . app . post ( '/execute' , asyncHandler ( async ( req : express . Request , res : express . Response ) => {
252253 if ( ! doRequestValidation ( req , res , [ 'environmentId' , 'containerId' , 'command' ] ) ) {
253254 return res . end ( )
254255 }
@@ -269,9 +270,9 @@ expressWs.app.post('/execute', async (req: express.Request, res: express.Respons
269270 return res . json ( {
270271 output : await env . execute ( sessionParameters , req . body . daemonize === true )
271272 } )
272- } )
273+ } ) )
273274
274- expressWs . app . post ( '/stop' , async ( req : express . Request , res : express . Response ) => {
275+ expressWs . app . post ( '/stop' , asyncHandler ( async ( req : express . Request , res : express . Response ) => {
275276 // req: some JSON -> with container ID that will stop the container
276277 if ( ! doRequestValidation ( req , res , [ 'environmentId' , 'containerId' ] ) ) {
277278 return res . end ( )
@@ -303,9 +304,9 @@ expressWs.app.post('/stop', async (req: express.Request, res: express.Response)
303304 error : `Container ${ containerId } was not stopped.`
304305 } )
305306 }
306- } )
307+ } ) )
307308
308- expressWs . app . post ( '/container-status' , async ( req : express . Request , res : express . Response ) => {
309+ expressWs . app . post ( '/container-status' , asyncHandler ( async ( req : express . Request , res : express . Response ) => {
309310 // req: some JSON -> with container ID that will stop the container
310311 if ( ! doRequestValidation ( req , res , [ 'environmentId' , 'containerId' ] ) ) {
311312 return res . end ( )
@@ -328,7 +329,7 @@ expressWs.app.post('/container-status', async (req: express.Request, res: expres
328329 status : ContainerStatus [ await env . containerIsRunning ( containerId ) ? ContainerStatus . RUNNING : ContainerStatus . STOPPED ]
329330 }
330331 ) . end ( )
331- } )
332+ } ) )
332333
333334// Error handling middleware
334335app . use ( ( error : Error , req : express . Request , res : express . Response , next : any ) => {
0 commit comments