go-aah / aah

A secure, flexible, rapid Go web framework
https://aahframework.org
MIT License
690 stars 33 forks source link

Routes behavior with&without a root (/) route is inconsistent #258

Closed joelsdc closed 4 years ago

joelsdc commented 5 years ago

What version of aah are you using (aah --version)?

v0.12.3

Does this issue reproduce with the latest release?

Yes

What operating system are you using (such as macOS, Linux and Windows)?

macOS (haven't verified the bug on other platforms)

What did you do?

Create a simple service that has only one route not directly under the root path.

Example routes.conf:

    routes {
      test {
        path = "/test/:something"
        controller = "SomeController"
        action = "SomeAction"
        }
      }
    }

What did you expect to see?

I expected that any path that wouldn't match .../test/something aah should return a 404, and the log should state a "route not found".

Expected:

GET http://localhost:8080 --> Route not found, Host: localhost:8080, Path: /
GET http://localhost:8080/ --> Route not found, Host: localhost:8080, Path: /
GET http://localhost:8080/a --> Route not found, Host: localhost:8080, Path: /a
GET http://localhost:8080/b --> Route not found, Host: localhost:8080, Path: /b
GET http://localhost:8080/asdf --> Route not found, Host: localhost:8080, Path: /asdf
GET http://localhost:8080/t --> Route not found, Host: localhost:8080, Path: /t
GET http://localhost:8080/te --> Route not found, Host: localhost:8080, Path: /te
GET http://localhost:8080/test --> Route not found, Host: localhost:8080, Path: /test (??)
GET http://localhost:8080/test/asdf --> Calling action: xxx/SomeController.SomeAction
GET http://localhost:8080/anything --> Route not found, Host: localhost:8080, Path: /anything
GET http://localhost:8080/something/else --> Route not found, Host: localhost:8080, Path: /something/else

NOTE: I have my doubts on what would the correct results be the line with (??)

What did you see instead?

I saw the following:

GET http://localhost:8080 --> Route not found, Host: localhost:8080, Path: /
GET http://localhost:8080/ --> Route not found, Host: localhost:8080, Path: /
GET http://localhost:8080/a --> Calling action: xxx/SomeController.SomeAction
GET http://localhost:8080/b --> Calling action: xxx/SomeController.SomeAction
GET http://localhost:8080/asdf --> Calling action: xxx/SomeController.SomeAction
GET http://localhost:8080/t --> Route not found, Host: localhost:8080, Path: /t
GET http://localhost:8080/te --> Route not found, Host: localhost:8080, Path: /te
GET http://localhost:8080/test --> Route not found, Host: localhost:8080, Path: /test
GET http://localhost:8080/test/asdf --> Route not found, Host: localhost:8080, Path: /test/asdf
GET http://localhost:8080/anything --> Calling action: xxx/SomeController.SomeAction
GET http://localhost:8080/something/else --> Route not found, Host: localhost:8080, Path: /something/else

Additional context

WORKAROUND: After extensive testing and trying crazy combinations I have found that if you have and "Index" route (/), this whole behavior changes:

Example2 routes.conf:

    routes {
      index {
        path = "/"
        controller = "DummyController"
        action = "DummyAction"
      }
      test {
        path = "/test/:something"
        controller = "SomeController"
        action = "SomeAction"
        }
      }
    }

We get the correct results:

GET http://localhost:8080 --> Calling action: xxx/DummyController.DummyAction
GET http://localhost:8080/ --> Calling action: xxx/DummyController.DummyAction
GET http://localhost:8080/a --> Route not found, Host: localhost:8080, Path: /a
GET http://localhost:8080/b --> Route not found, Host: localhost:8080, Path: /b
GET http://localhost:8080/asdf --> Route not found, Host: localhost:8080, Path: /asdf
GET http://localhost:8080/t --> Route not found, Host: localhost:8080, Path: /t
GET http://localhost:8080/te --> Route not found, Host: localhost:8080, Path: /te
GET http://localhost:8080/test --> Route not found, Host: localhost:8080, Path: /test
GET http://localhost:8080/test/asdf --> Calling action: xxx/SomeController.SomeAction
GET http://localhost:8080/anything --> Route not found, Host: localhost:8080, Path: /anything
GET http://localhost:8080/something/else --> Route not found, Host: localhost:8080, Path: /something/else

Please let me know if you need any other information.

Thanks!

jeevatkm commented 5 years ago

@joelsdc I have read your details bug report. Thank you for explaining in detail.

I feel this is bug in the router when route / is not defined. Need investigation and fix!

jeevatkm commented 4 years ago

@joelsdc I hope you're doing well. I'm trying to wrap up the v0.13.0 release. Did fixes and enhancements. Then I will be moving on to aah revamp on v0.14.0

Can you please validate this issue against the branch wrapping-v0.13.0 and let me know?