File tree 2 files changed +25
-6
lines changed
2 files changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -52,18 +52,31 @@ export function execute(opts) {
52
52
} ;
53
53
54
54
export function watch ( opts ) {
55
+ if ( ! opts . verboseLevel ) {
56
+ opts . verboseLevel = 0 ;
57
+ }
55
58
const server = createServer ( async function ( req : IncomingMessage , res : ServerResponse ) {
59
+ var log_msg = `${ req . method } ${ req . headers . host } ${ req . url } ` ;
60
+ function handle_error ( error ) {
61
+ logger . log ( 'warn' , log_msg + ` -> ${ error } ` ) ;
62
+ res . statusCode = 500 ;
63
+ return res . end ( JSON . stringify ( { error } ) ) ;
64
+ }
56
65
try {
57
66
if ( req . headers [ 'content-type' ] !== 'application/json' ) throw 'Invalid header Content-Type (Expected application/json)' ;
58
- if ( req . method !== 'POST' ) throw 'Invalid http method (Expected POST)' ;
59
67
_getRequestPayload ( req , async ( error , result ) => {
60
- if ( error ) throw error ;
61
- const data = await execute ( { ...opts , event : ( ) => result } )
62
- return res . end ( JSON . stringify ( { data } ) ) ;
68
+ try {
69
+ if ( error ) throw error ;
70
+ const data = await execute ( { ...opts , event : ( ) => result } ) ;
71
+ const ans = JSON . stringify ( { data } ) ;
72
+ logger . log ( 'info' , log_msg + ` -> OK (${ ans . length * 2 } bytes)` ) ;
73
+ return res . end ( ans ) ;
74
+ } catch ( error ) {
75
+ return handle_error ( error ) ;
76
+ }
63
77
} ) ;
64
78
} catch ( error ) {
65
- res . statusCode = 500 ;
66
- return res . end ( JSON . stringify ( { error } ) ) ;
79
+ return handle_error ( error ) ;
67
80
}
68
81
} ) ;
69
82
server . listen ( opts . port , function ( ) {
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Lambda function used for basic test.
3
+ */
4
+ exports . handler = function ( event , context ) {
5
+ context . succeed ( event ) ;
6
+ } ;
You can’t perform that action at this time.
0 commit comments