Repository navigation
Add support for prefix matching routing - #143
Conversation
This allows customers that have inline Swagger definitions with proxy setup to work with SAM local. This also adds support for: * correctly handling multi-line output * correctly handling non-existent static directories * correctly marshalling event fields that are empty
|
|
||
| methods := []string{"OPTIONS", "GET", "HEAD", "POST", "PUT", "DELETE", "TRACE", "CONNECT"} | ||
| for _, method := range methods { | ||
| It("should respond to HTTP requests on "+method+" /any", func() { |
There was a problem hiding this comment.
Amazing test! I get super excited when seeing such thorough tests. Love it!
sanathkr
left a comment
There was a problem hiding this comment.
This is awesome! I think we can be more standard in how we support prefix paths.
| Type: "Api", | ||
| Properties: &cloudformation.AWSServerlessFunction_S3EventOrSNSEventOrKinesisEventOrDynamoDBEventOrApiEventOrScheduleEventOrCloudWatchEventEventOrIoTRuleEventOrAlexaSkillEvent{ | ||
| ApiEvent: &cloudformation.AWSServerlessFunction_ApiEvent{ | ||
| Path: "/any", |
There was a problem hiding this comment.
Actually, prefix routing should be automatically enabled when route is /foo/bar/{path}+. See: https://aws.amazon.com/blogs/aws/api-gateway-update-new-features-simplify-api-development/.
It should be fairly simple change to make: In router.go, just check for path containing catch-alls and enable prefix routing on the prefix ie. /foo/bar/{path}+ would enable prefix routing on /foo/bar
There was a problem hiding this comment.
Updated pull request to include this functionality. Basically if we detect that a path ends with a catch all variables (e.g. {foo+} we instruct the mount to use prefix matching.
I added this functionality to the ServerlessRouterMount to better decouple the implementation (i.e. router) from the metadata (i.e. mount).
Let me know what you think.
|
|
||
| // parseOutput decodes the proxy response from the output of the function and returns | ||
| // the rest | ||
| func parseOutput(w http.ResponseWriter, stdoutTxt io.Reader, runtime string, wg *sync.WaitGroup) (output []byte) { |
| var out []byte | ||
| var r *fakeResponse | ||
|
|
||
| // cases: error on output, non-json, empty output, missing bodym headers or status, |
This allows customers that have inline Swagger definitions with proxy setup to work with SAM local.
For example if a customer has a lambda mounted at
/foowith an inline Swagger that has an API/barpreviously requests to/foo/barwould have resulted in a404response, but now the lambda is invoked as expected.To use this functionality, the customer must opt-in on it using
--prefix-routingflagThis also adds support for: