Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit cc00685

Browse files
committed
fix(serve): Added fallback to get JWT from URL 'token' parameter if it is not set in headers
1 parent bb85f81 commit cc00685

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/serve.ts

+22-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,17 @@ if (JWT_ENABLED) {
2929
throw Error('JWT_SECRET must be set')
3030
}
3131

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+
}))
3343
}
3444

3545
/**
@@ -164,7 +174,7 @@ expressWs.app.ws('/shell', async (ws: any, req: express.Request) => {
164174
}
165175
})
166176

167-
// Instantiate shell and set up data handlers
177+
// Instantiate shell and set up data handlers but connect to an existing container
168178
expressWs.app.ws('/interact', async (ws: any, req: express.Request) => {
169179
const environment = req.query.environment || DEFAULT_ENVIRONMENT
170180
const containerId = req.query.containerId || ''
@@ -224,6 +234,14 @@ expressWs.app.post('/start', async (req: express.Request, res: express.Response)
224234
sessionParameters.platform = Platform.DOCKER
225235
sessionParameters.command = req.body.command || ''
226236

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+
227245
const containerId = await env.start(sessionParameters)
228246
return res.json({
229247
containerId: containerId
@@ -288,6 +306,8 @@ expressWs.app.post('/stop', async (req: express.Request, res: express.Response)
288306

289307
})
290308

309+
// TODO: session (container) info querying (i.e. is container still running)
310+
291311
// Error handling middleware
292312
app.use((error: Error, req: express.Request, res: express.Response, next: any) => {
293313
console.error(error.stack)

0 commit comments

Comments
 (0)