Nitrogen/Webmachine dispatch and path_info question

71 views
Skip to first unread message

kevin montuori

unread,
Aug 15, 2011, 6:57:03 PM8/15/11
to nitro...@googlegroups.com
All --

I think I'm misunderstanding something about either Nitrogen or Webmachine and I'm hoping someone can clarify.  

I have a nitrogen_webmachine:dispatch/0 that reads:

dispatch() -> 
    [
     {["css", '*'], static_resource, [{root, "./site/static/css"}]},
     {["images", '*'], static_resource, [{root, "./site/static/images"}]},
     {["nitrogen", '*'], static_resource, [{root, "./site/static/nitrogen"}]},
     {['test', '*'], ?MODULE, testpage},
     {['*'], static_resource, [{root, "./site/static"}]}
    ].

I am expecting that with this dispatch table and a request to /test/a/b/c I'd see that wf:path_info/0 would return "a/b/c".  With my setup it's returning 'undefined'.  Note that if I stick to the default dispatch table:

{["css", '*'], static_resource, [{root, "./site/static/css"}]},
{["images", '*'], static_resource, [{root, "./site/static/images"}]},
{["nitrogen", '*'], static_resource, [{root, "./site/static/nitrogen"}]} 
{['*'], ?MODULE, dynamic_route_handler}

I see the path_info data being set as I'd expect.  Any pointers to where I'm going wrong?

Thanks!
k. 

Jesse Gumm

unread,
Aug 17, 2011, 9:39:13 AM8/17/11
to nitro...@googlegroups.com
I'll admit I've never played with the dispatch part of the webmachine
aspect of nitrogen, but in the code I have, dispatch()/0 is in
nitrogen_sup.erl and not nitrogen_webmachine.erl.

I suspect what it's doing is rewriting the url to just /testpage and
not passing the PathInfo which is parsed out in the
dynamic_route_handler, though I'll admit I'm not positive without
digging in further.


Personally, I think you'd be better off making a custom dynamic_route_handler.

1) Copy https://github.com/nitrogen/nitrogen_core/blob/master/src/handlers/route/dynamic_route_handler.erl
into your src directory somewhere, renaming it to something else (ie:
my_dyn_route_handler.erl), remember to change the -module() header as
well,

2) Modify that new route handler to include a new section:

route([$t,$e,$s,$t,$/ | PathInfo]) ->
{testpage,PathInfo}.

3) Modify nitrogen_sup.erl and nitrogen_webmachine.erl, changing all
references to 'dynamic_route_handler' to 'my_dyn_route_handler'


This would make it more easily portable to other webservers (should
you decide to switch to mochiweb or whatever).

-Jesse

> --
> You received this message because you are subscribed to the Google Groups
> "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/nitrogenweb/-/GUYLzhTCMfYJ.
> To post to this group, send email to nitro...@googlegroups.com.
> To unsubscribe from this group, send email to
> nitrogenweb...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/nitrogenweb?hl=en.
>

--
Jesse Gumm
Sigma Star Systems
414.940.4866
gu...@sigma-star.com
http://www.sigma-star.com

Reply all
Reply to author
Forward
0 new messages