Question regarding Apex and paths

245 views
Skip to first unread message

Arnaud Estève

unread,
Feb 5, 2015, 5:09:35 AM2/5/15
to ve...@googlegroups.com
Hi,

I'm trying to play with Vert.x 3 and Apex with static server and PathTemplateHandler.

Let's say I have a staticServer mapped on "/static" and a template handler mapped on "/dynamic" (as mentionned in the docs).

If I try to get the following URL : "/static/img/my_img.png" I think the static server will look for the resource in webroot/static/img/my_img.png. Is this intended ?

(same behaviour with PathTemplateHandler which will look for templates into templateDir/dynamic/myPage.jade for /dynamic/myPage for instance)

Am I missing something or is this just a bug ? (in this case I'll file an issue)

Thanks.

Tim Fox

unread,
Feb 5, 2015, 7:45:48 AM2/5/15
to ve...@googlegroups.com
On 05/02/15 10:09, Arnaud Estève wrote:
Hi,

I'm trying to play with Vert.x 3 and Apex with static server and PathTemplateHandler.

Let's say I have a staticServer mapped on "/static" and a template handler mapped on "/dynamic" (as mentionned in the docs).

If I try to get the following URL : "/static/img/my_img.png" I think the static server will look for the resource in webroot/static/img/my_img.png. Is this intended ?

(same behaviour with PathTemplateHandler which will look for templates into templateDir/dynamic/myPage.jade for /dynamic/myPage for instance)

Not sure I understand what the issue is.. can you elaborate? Do you want resources served from elsewhere?


Am I missing something or is this just a bug ? (in this case I'll file an issue)

Thanks.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Arnaud Estève

unread,
Feb 5, 2015, 8:07:49 AM2/5/15
to ve...@googlegroups.com
Maybe I'm looking at it the wrong way but let's imagine we have :

route("/static").handler(staticServer);

Then : GET /static/img/my-image.png 

should serve the file located into : webroot/img/my-image.png 

and not : webroot/static/img/my-image.png

Because when I declare the routing I understand it like that : "the /static route points directly to the webroot folder".

Maybe this way of thinking is biased by the way the resources plugins work in both RoR and Grails. ("/static" is directly mapped onto a resource folder).

But maybe in Apex case it's not desirable (question behind is : which behaviour we'd want if we map two different routes on our staticServer)

Is it a little bit more clear ?

Asher Tarnopolski

unread,
Feb 5, 2015, 8:15:31 AM2/5/15
to ve...@googlegroups.com
this is the expected behavior. your entire uri is treated as a path to your resources, which in their turn is looked up under the webRoot.

Tim Fox

unread,
Feb 5, 2015, 10:17:59 AM2/5/15
to ve...@googlegroups.com
On 05/02/15 13:07, Arnaud Estève wrote:
Maybe I'm looking at it the wrong way but let's imagine we have :

route("/static").handler(staticServer);

Then : GET /static/img/my-image.png 

should serve the file located into : webroot/img/my-image.png

Why not just do:

router.route().handler(staticServer);

Then : GET /img/my-image.png 

will serve the file located into : webroot/img/my-image.png

Or, if you really want the "static" in the url then you can use a subrouter:

router.mountSubrouter("/static/", Router.route().handler(staticServer));

Then : GET /static/img/my-image.png 

will also serve the file located into : webroot/img/my-image.png

Arnaud Estève

unread,
Feb 5, 2015, 10:44:55 AM2/5/15
to ve...@googlegroups.com
Thanks to you both.

Subrouter must be the way to go for me (and it works indeed), since I'd like the default path to be mapped on dynamic pages served with PathTemplateHandler.

I think I still understand pretty bad the way Apex and routers should be used, it should be better once the docs are out :)

Tim Fox

unread,
Feb 5, 2015, 10:50:07 AM2/5/15
to ve...@googlegroups.com
We could change StaticServer to work like you expect (i.e. only use the sub path from the mount point of the route). At this point I'm not really sure which approach makes more sense...

Deven Phillips

unread,
Mar 2, 2015, 9:58:25 PM3/2/15
to ve...@googlegroups.com
It may also make sense to expose a way to specify a webroot which is NOT inside of the source tree... For example, be able to specify something starting from the root of the filesystem (i.e. /var/www/html)...

Deven

Tim Fox

unread,
Mar 3, 2015, 3:21:22 AM3/3/15
to ve...@googlegroups.com
Webroot's don't have to be inside of a source tree. I wonder if you could be a bit more specific about what is not working as you would expect?


On 03/03/15 02:58, Deven Phillips wrote:
It may also make sense to expose a way to specify a webroot which is NOT inside of the source tree... For example, be able to specify something starting from the root of the filesystem (i.e. /var/www/html)...

Deven

Deven Phillips

unread,
Mar 4, 2015, 2:57:14 PM3/4/15
to ve...@googlegroups.com
When I tried to use the StaticHandler to specify a path with a leading slash I got an error... I will try again and post back with the error message.

Deven

--
You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/zpYu2XleYeI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vertx+un...@googlegroups.com.

Deven Phillips

unread,
Mar 4, 2015, 4:56:01 PM3/4/15
to ve...@googlegroups.com
Here's the example I spoke of earlier:

Router router = Router.router(vertx);
router.route(GET, "/some/path/").handler(StaticHandler.create("/tmp/html"));


And when it runs, I get this error:

Mar 04, 2015 4:53:06 PM io.vertx.core.impl.DeploymentManager
SEVERE: Failure in calling handler
java.lang.IllegalArgumentException: root cannot start with '/'
    at io.vertx.ext.apex.handler.impl.StaticHandlerImpl.setRoot(StaticHandlerImpl.java:373)
    at io.vertx.ext.apex.handler.impl.StaticHandlerImpl.<init>(StaticHandlerImpl.java:74)
    at io.vertx.ext.apex.handler.StaticHandler.create(StaticHandler.java:113)
    at com.zanclus.vertx.nexus.proxy.Main.configureHttpRequestRouter(Main.java:302)
    at com.zanclus.vertx.nexus.proxy.Main.lambda$9(Main.java:107)
    at com.zanclus.vertx.nexus.proxy.Main$$Lambda$14/150417916.handle(Unknown Source)
    at io.vertx.core.impl.DeploymentManager.lambda$reportResult$107(DeploymentManager.java:389)
    at io.vertx.core.impl.DeploymentManager$$Lambda$13/2045274517.handle(Unknown Source)
    at io.vertx.core.impl.ContextImpl.lambda$wrapTask$28(ContextImpl.java:260)
    at io.vertx.core.impl.ContextImpl$$Lambda$4/1123629720.run(Unknown Source)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:380)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
    at java.lang.Thread.run(Thread.java:745)

Deven Phillips

unread,
Mar 4, 2015, 5:25:05 PM3/4/15
to ve...@googlegroups.com
Additionally, I just tried to do:

        StaticHandler sHandler = StaticHandler
                                    .create("webroot")
                                    .setDirectoryListing(false)
                                    .setIndexPage("index.html")
                                    .setFilesReadOnly(true)
                                    .setCachingEnabled(true)
                                    .setAlwaysAsyncFS(true);
        router.route(GET, "/some/path/")
                .handler(sHandler);

But when I request http://myserver/some/path/ I get 403 Forbidden instead of the expected index.html page...

Deven

Arnaud Estève

unread,
Mar 8, 2015, 6:30:38 AM3/8/15
to ve...@googlegroups.com
I got the exact same issue while I was trying to deploy an app on a Linux machine.

I wanted webroot to be mapped on an absolute Linux path and got the same "cannot start with '/'" error.

Is it forbidden ?

Geoffrey Clements

unread,
Mar 9, 2015, 9:31:23 PM3/9/15
to ve...@googlegroups.com
Like routers in most web frameworks, getting a feel for how they REALLY work is going to take a while and a lot of examples.

I've been trying to segment my router so it feels a bit like rails. Sort of. I'm using Thymeleaf templates and my router looks like:

// if you are getting a products page get products using a naive ORM
router.get("/products/*").handler(context -> {
    Product.all(mongoService, res -> {
        if (res.succeeded()) {
            context.put("products", res.result());
            context.next();
        } else {
            context.fail(res.cause());
        }
    });
});

// now the products template from template/products
router.route("/products/*").handler(
TemplateHandler.create(ThymeleafTemplateEngine.create().setMode("HTML5"),
"templates/products", "text/html"));

// everything else css/*.css images/* favicon.ico etc. out of webroot
router.route().handler(StaticHandler.create());

It's a bit messy since I'm flailing around a bit figuring out how things work, but if you'd like a look, the repository is here: https://github.com/baldmountain/vertx-depot


geoff

Tim Fox

unread,
Mar 13, 2015, 7:23:59 AM3/13/15
to ve...@googlegroups.com
Looks very interesting :)

Geoffrey Clements

unread,
Mar 13, 2015, 10:24:41 AM3/13/15
to ve...@googlegroups.com
Actually, have another look. I checked in some changes this morning so the cart now works. Controllers are broken out into their own classes, setup their own routes, and have their own template handler. There are a lot of interesting cases where operations need to happen in a certain order and the server needs to wait until something finishes. There are still lots of bugs, and it is possible to get to a place where the server gets stuck or lost, but it seems to work. Mostly. :)


geoff


On Friday, March 13, 2015 at 7:23:59 AM UTC-4, Tim Fox wrote:
Looks very interesting :)


Reply all
Reply to author
Forward
0 new messages