Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
qrman committed Oct 24, 2019
1 parent 7e5a87a commit bf078a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class SimpleRouteTest {
@Test
public void testSimpleRoute() {
RestAssured.when().get("/hello").then().statusCode(200).body(is("Hello world!"));
RestAssured.when().get("/no-slash").then().statusCode(200).body(is("Hello world!"));
RestAssured.when().get("/rx-hello").then().statusCode(200).body(is("Hello world!"));
RestAssured.when().get("/bzuk").then().statusCode(200).body(is("Hello world!"));
RestAssured.when().get("/hello-event-bus?name=ping").then().statusCode(200).body(is("Hello PING!"));
Expand All @@ -48,6 +49,7 @@ static class SimpleBean {

@Route(path = "/hello")
@Route(path = "/foo")
@Route(path = "no-slash")
void hello(RoutingContext context) {
String name = context.request().getParam("name");
context.response().setStatusCode(200).end("Hello " + (name != null ? name : "world") + "!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public io.vertx.ext.web.Route apply(Router router) {
if (!routeAnnotation.regex().isEmpty()) {
route = router.routeWithRegex(routeAnnotation.regex());
} else if (!routeAnnotation.path().isEmpty()) {
route = router.route(routeAnnotation.path());
route = router.route(ensureStartWithSlash(routeAnnotation.path()));
} else {
route = router.route();
}
Expand Down Expand Up @@ -92,4 +92,13 @@ public void handle(RoutingContext event) {
}
};
}

private String ensureStartWithSlash(String path) {
if (path.startsWith("/")) {
return path;
} else {
return "/" + path;
}
}

}

0 comments on commit bf078a4

Please sign in to comment.