You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
and every other combination of prefixes I have been able to come up with. Further, adding some logging in the generated class Function extends AzureHttpFunction class, we can see that only requests with context path /api are actually hitting the method in the Function class (which I in this report call the "router function"), even after we have defined a different context path.
This this makes it impossible to actually hit the controller function in the generated HelloController since:
you will only get routed if you hit /api/...
you will only match any existing route if your uri matches /foo (it's actually even worse, you need to match /foo/foo/hello, more on this below)
Further, adding a breakpoint in the class io.micronaut.web.router.DefaultRouter, method find:
private <T, R> List<UriRouteMatch<T, R>> find(String httpMethodName, CharSequence uri) {
List<UriRoute> routes = routesByMethod.getOrDefault(httpMethodName, Collections.emptyList());
if (CollectionUtils.isNotEmpty(routes)) { // <-------- BREAKPOINT HERE
final String uriStr = uri.toString();
we can see that with the above setup, i.e. with:
newly generated azure function project with a Function and a HelloController with @Controller('/hello') and @Get(uri="/")
a application.yml change setting the context path to /foo
running the function locally using the azure core tools and gradle task azureFunctionsRun
, the routes variable gets one route:
GET /foo/foo/hello -> HelloController#io.micronaut.context.DefaultBeanContext$4@7615e40f (application/json )
so to sum things up:
we have to hit /api as otherwise our request doesn't get routed at all
this is true even if we have manually changed the context path
changing the context path to anything, creates two problems:
we can never hit the url as it no longer starts with /api
the context path is duplicated in the micronaut-internal registered route. I.e. it doesn't say /foo/hello it says /foo/foo/hello
Expected Behaviour
Being able to change the root context path and still have functions work.
Actual Behaviour
Changing the context path breaks azure http functions.
Environment Information
─➤ mn --version 130 ↵
Micronaut Version: 2.0.0
JVM Version: 1.8.0_252
─➤ ./gradlew --version 130 ↵
------------------------------------------------------------
Gradle 6.5
------------------------------------------------------------
Build time: 2020-06-02 20:46:21 UTC
Revision: a27f41e4ae5e8a41ab9b19f8dd6d86d7b384dad4
Kotlin: 1.3.72
Groovy: 2.5.11
Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM: 1.8.0_252 (Amazon.com Inc. 25.252-b09)
OS: Linux 5.4.0-39-generic amd64
With this in place you can write regular Micronaut controllers as documented in the user guide for the HTTP server and incoming function requests will be routed to the controllers and executed.
nowhere do we mention the /api prefix, the fact that it doesn't seem like it can be changed, etc. It would be helpful to have a few examples of how to curl things and actually hit the controller so as not to make users have to experiment to figure out where the controller route actually lives.
Happy to make a pr for the docs once this issue has been resolved.
The text was updated successfully, but these errors were encountered:
Sample Repository
https://bitbucket.org/mbjarland/azure-function-context-path-issue/src/master/
Steps to Reproduce
When it works:
in a separate terminal:
When it breaks:
Edit
src/main/resources/application.yml
and add:and run again:
in a separate terminal:
i.e. we get a http 404 not found response. The same result with:
and every other combination of prefixes I have been able to come up with. Further, adding some logging in the generated
class Function extends AzureHttpFunction
class, we can see that only requests with context path/api
are actually hitting the method in theFunction
class (which I in this report call the "router function"), even after we have defined a different context path.This this makes it impossible to actually hit the controller function in the generated HelloController since:
/api/...
/foo
(it's actually even worse, you need to match/foo/foo/hello
, more on this below)Further, adding a breakpoint in the class
io.micronaut.web.router.DefaultRouter
, methodfind
:we can see that with the above setup, i.e. with:
Function
and aHelloController
with@Controller('/hello')
and@Get(uri="/")
/foo
azureFunctionsRun
, the
routes
variable gets one route:so to sum things up:
/api
as otherwise our request doesn't get routed at all/api
/foo/hello
it says/foo/foo/hello
Expected Behaviour
Being able to change the root context path and still have functions work.
Actual Behaviour
Changing the context path breaks azure http functions.
Environment Information
A Note on Documentation
at:
https://micronaut-projects.github.io/micronaut-azure/1.0.x/guide/
we state the following:
nowhere do we mention the
/api
prefix, the fact that it doesn't seem like it can be changed, etc. It would be helpful to have a few examples of how to curl things and actually hit the controller so as not to make users have to experiment to figure out where the controller route actually lives.Happy to make a pr for the docs once this issue has been resolved.
The text was updated successfully, but these errors were encountered: