File tree Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Expand file tree Collapse file tree 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) {
5252} ;
5353
5454export function watch ( opts ) {
55+ if ( ! opts . verboseLevel ) {
56+ opts . verboseLevel = 0 ;
57+ }
5558 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+ }
5665 try {
5766 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)' ;
5967 _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+ }
6377 } ) ;
6478 } catch ( error ) {
65- res . statusCode = 500 ;
66- return res . end ( JSON . stringify ( { error } ) ) ;
79+ return handle_error ( error ) ;
6780 }
6881 } ) ;
6982 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