@@ -5,6 +5,11 @@ const webpack = require('webpack');
5
5
const express = require ( 'express' ) ;
6
6
const bodyParser = require ( 'body-parser' ) ;
7
7
8
+ const supportedMethods = 'get post' . split ( ' ' ) ;
9
+ const resolveMethods = ( method ) => ( method . toLowerCase ( ) === 'any'
10
+ ? supportedMethods
11
+ : [ method . toLowerCase ( ) ] ) ;
12
+
8
13
module . exports = {
9
14
serve ( ) {
10
15
this . serverless . cli . log ( 'Serving functions...' ) ;
@@ -44,24 +49,24 @@ module.exports = {
44
49
45
50
for ( let funcConf of funcConfs ) {
46
51
for ( let httpEvent of funcConf . events ) {
47
- const method = httpEvent . method . toLowerCase ( ) ;
48
- let endpoint = `/${ httpEvent . path } ` ;
52
+ let endpoint = `/${ httpEvent . path } ` . replace ( / ^ \/ + / , '/' ) ;
49
53
if ( this . options . stage ) {
50
54
endpoint = `/${ this . options . stage } ${ endpoint } ` ;
51
55
}
52
- const path = endpoint . replace ( / \{ ( .+ ?) \} / g, ':$1' ) ;
56
+ const path = endpoint
57
+ . replace ( / \{ p r o x y \+ \} / , '*' )
58
+ . replace ( / \{ ( .+ ?) \} / g, ':$1' ) ;
53
59
let handler = this . _handlerBase ( funcConf , httpEvent ) ;
54
60
let optionsHandler = this . _optionsHandler ;
55
61
if ( httpEvent . cors ) {
56
62
handler = this . _handlerAddCors ( handler ) ;
57
63
optionsHandler = this . _handlerAddCors ( optionsHandler ) ;
58
64
}
59
65
app . options ( path , optionsHandler ) ;
60
- app [ method ] (
61
- path ,
62
- handler
63
- ) ;
64
- this . serverless . cli . consoleLog ( ` ${ method . toUpperCase ( ) } - http://localhost:${ this . _getPort ( ) } ${ endpoint } ` ) ;
66
+ for ( let method of resolveMethods ( httpEvent . method ) ) {
67
+ app [ method ] ( path , handler ) ;
68
+ }
69
+ this . serverless . cli . consoleLog ( ` ${ httpEvent . method . toUpperCase ( ) } - http://localhost:${ this . _getPort ( ) } ${ endpoint } ` ) ;
65
70
}
66
71
}
67
72
0 commit comments