Skip to content

Add support for prefix matching routing - #143

Merged
PaulMaddox merged 15 commits into
aws:developfrom
resios:develop
Oct 5, 2017
Merged

PaulMaddox merged 15 commits into
aws:developfrom
resios:develop

Conversation

@resios

@resios resios commented Sep 27, 2017 •

Copy link
Copy Markdown
Contributor

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 /foo with an inline Swagger that has an API /bar previously requests to /foo/bar would have resulted in a 404 response, but now the lambda is invoked as expected.

To use this functionality, the customer must opt-in on it using --prefix-routing flag

This also adds support for:

Comment thread router/function_test.go

methods := []string{"OPTIONS", "GET", "HEAD", "POST", "PUT", "DELETE", "TRACE", "CONNECT"}
for _, method := range methods {
It("should respond to HTTP requests on "+method+" /any", func() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing test! I get super excited when seeing such thorough tests. Love it!

@sanathkr sanathkr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! I think we can be more standard in how we support prefix paths.

Comment thread router/function_test.go
Type: "Api",
Properties: &cloudformation.AWSServerlessFunction_S3EventOrSNSEventOrKinesisEventOrDynamoDBEventOrApiEventOrScheduleEventOrCloudWatchEventEventOrIoTRuleEventOrAlexaSkillEvent{
ApiEvent: &cloudformation.AWSServerlessFunction_ApiEvent{
Path: "/any",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread runtime.go

// 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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!!

Comment thread runtime_test.go Outdated
var out []byte
var r *fakeResponse

// cases: error on output, non-json, empty output, missing bodym headers or status,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@sanathkr

sanathkr commented Sep 29, 2017 •

Copy link
Copy Markdown

I think this PR fixes more stuff: #65, #39, #141, #45

@PaulMaddox
PaulMaddox self-requested a review October 4, 2017 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants