Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unintuitive routes #65

Closed
funkybob opened this issue Jul 22, 2016 · 1 comment
Closed

Unintuitive routes #65

funkybob opened this issue Jul 22, 2016 · 1 comment
Labels

Comments

@funkybob
Copy link

I spent a couple of evenings trying to set up a chalice with two routes, always getting the same error:

botocore.exceptions.ClientError: An error occurred (BadRequestException) when calling the CreateResource operation: Resource's path part must be specified

After some trial and error, I discovered the following:

  1. The '/' route is a lie

If you ask for {hostname}/dev/ you will be rudely rejected.
If you ask for {hostname}/dev it will access route('/')

  1. Trailing / makes chalice cry.

Originally I had two routes:

    @app.route('/')

    @app.route('/login/')

And got the error above.

However, if I change the second route to @app.route('/login') it works.

Can anyone explain this? Or is this really a bug?

@jamesls
Copy link
Member

jamesls commented Jul 28, 2016

This appears to be a restriction on API gateway. For example, when I try to create a login/ resource in the console I get: Resource's path part only allow a-zA-Z0-9.- and curly braces at the beginning and the end._

It also seems that trailing slashes "work" without explicitly declaring them.

Given:

@app.route('/trailing-slash')
def viewtest():
    return {'success': True}

Then both of these work:

$ http https://1a9g3eqo44.execute-api.us-west-2.amazonaws.com/dev/trailing-slash
HTTP/1.1 200 OK


{
    "success": true
}


$ http https://1a9g3eqo44.execute-api.us-west-2.amazonaws.com/dev/trailing-slash/
HTTP/1.1 200 OK

{
    "success": true
}

So I see two options:

  • Add client side error checking to automatically fail if there's a route that ends with a /. Given instructions on how to fix it.
  • Automatically remove the trailing slash for the user and emit a warning that we're modifying one of their routes.

I'd propose going with option 1, it's more explicit and should be a quick fix for the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants