@@ -29,7 +29,17 @@ if (JWT_ENABLED) {
29
29
throw Error ( 'JWT_SECRET must be set' )
30
30
}
31
31
32
- app . use ( jwt ( { secret : JWT_SECRET } ) )
32
+ app . use ( jwt ( {
33
+ secret : JWT_SECRET ,
34
+ getToken : function fromHeaderOrQuerystring ( req : express . Request ) {
35
+ if ( req . headers . authorization && req . headers . authorization . split ( ' ' ) [ 0 ] === 'Bearer' ) {
36
+ return req . headers . authorization . split ( ' ' ) [ 1 ]
37
+ } else if ( req . query && req . query . token ) {
38
+ return req . query . token
39
+ }
40
+ return null
41
+ }
42
+ } ) )
33
43
}
34
44
35
45
/**
@@ -164,7 +174,7 @@ expressWs.app.ws('/shell', async (ws: any, req: express.Request) => {
164
174
}
165
175
} )
166
176
167
- // Instantiate shell and set up data handlers
177
+ // Instantiate shell and set up data handlers but connect to an existing container
168
178
expressWs . app . ws ( '/interact' , async ( ws : any , req : express . Request ) => {
169
179
const environment = req . query . environment || DEFAULT_ENVIRONMENT
170
180
const containerId = req . query . containerId || ''
@@ -224,6 +234,14 @@ expressWs.app.post('/start', async (req: express.Request, res: express.Response)
224
234
sessionParameters . platform = Platform . DOCKER
225
235
sessionParameters . command = req . body . command || ''
226
236
237
+ if ( req . body . cpuShares ) {
238
+ sessionParameters . cpuShares = req . body . cpuShares
239
+ }
240
+
241
+ if ( req . body . memoryLimit ) {
242
+ sessionParameters . memoryLimit = req . body . memoryLimit
243
+ }
244
+
227
245
const containerId = await env . start ( sessionParameters )
228
246
return res . json ( {
229
247
containerId : containerId
@@ -288,6 +306,8 @@ expressWs.app.post('/stop', async (req: express.Request, res: express.Response)
288
306
289
307
} )
290
308
309
+ // TODO: session (container) info querying (i.e. is container still running)
310
+
291
311
// Error handling middleware
292
312
app . use ( ( error : Error , req : express . Request , res : express . Response , next : any ) => {
293
313
console . error ( error . stack )
0 commit comments