File tree Expand file tree Collapse file tree 3 files changed +19
-9
lines changed Expand file tree Collapse file tree 3 files changed +19
-9
lines changed Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env -S node --import ./lib/util/instrument.mjs
2
- console . log ( 'Starting stf ' )
2
+ console . log ( 'Starting DeviceHub ' )
3
3
import '../lib/cli/index.js'
Original file line number Diff line number Diff line change @@ -29,7 +29,6 @@ const request = Promise.promisifyAll(postmanRequest)
29
29
export default ( function ( options ) {
30
30
var log = logger . createLogger ( 'websocket' )
31
31
var server = http . createServer ( )
32
- console . log ( options )
33
32
// eslint-disable-next-line camelcase
34
33
const io_options = {
35
34
serveClient : false
Original file line number Diff line number Diff line change 1
1
import * as dbapi from '../../../db/api.js'
2
2
import * as jwtutil from '../../../util/jwtutil.js'
3
3
import * as cookie from 'cookie'
4
+ import logger from '../../../util/logger.js'
5
+
4
6
5
7
export default ( function ( options ) {
8
+ const log = logger . createLogger ( 'websocket' )
6
9
return function ( socket , next ) {
7
10
let req = socket . request
8
- let token
9
- const cookies = cookie . parse ( req . headers . cookie )
11
+ let token , cookies
12
+ try {
13
+ cookies = cookie . parse ( req . headers . cookie )
14
+ }
15
+ catch ( e ) {
16
+ return next ( new Error ( 'Missing authorization token' ) )
17
+ }
10
18
if ( cookies . token ) {
11
19
token = jwtutil . decode ( cookies . token , options . secret )
12
20
req . internalJwt = cookies . token
13
21
}
14
22
else {
15
- next ( new Error ( 'Missing authorization token' ) )
23
+ return next ( new Error ( 'Missing authorization token' ) )
16
24
}
17
25
if ( token ) {
18
26
return dbapi . loadUser ( token . email )
19
27
. then ( function ( user ) {
20
28
if ( user ) {
21
29
req . user = user
22
- next ( )
30
+ return next ( )
23
31
}
24
32
else {
25
- next ( new Error ( 'Invalid user' ) )
33
+ return next ( new Error ( 'Invalid user' ) )
26
34
}
27
35
} )
28
- . catch ( next )
36
+ . catch ( ( e ) => {
37
+ log . error ( e )
38
+ return next ( new Error ( 'Unknown error' ) )
39
+ } )
29
40
}
30
41
else {
31
- next ( new Error ( 'Missing authorization token' ) )
42
+ return next ( new Error ( 'Missing authorization token' ) )
32
43
}
33
44
}
34
45
} )
You can’t perform that action at this time.
0 commit comments