Hi Rodrigo,
This is an interesting idea, and not one pursued too deeply in the past.
I believe it can be doable, but it may be a little finnicky and will
certainly require some trial and error:
My gut is telling me that the best approach is this:
1) Pick a backend (cowboy, yaws, whatever)
2) Deploy a custom simple_bridge anchor module based on the backend's
anchor module (example:
https://github.com/nitrogen/simple_bridge/blob/master/src/cowboy_bridge_modules/cowboy_simple_bridge_anchor.erl),
which would then choose the "handler" module with the desired one
based on the URL as retrieved from the Req objects, rather than
choosing the handler from the application env vars (as it does here:
https://github.com/nitrogen/simple_bridge/blob/master/src/cowboy_bridge_modules/cowboy_simple_bridge_anchor.erl#L30-L49)
CB's simple_bridge handler is 'boss_simple_bridge_handler'
Nitrogen's simple_bridge handler is the module 'nitrogen'
You could probably make a function like:
routed_handler_mod(Req) ->
case cowboy_req:path(Req) of
{"api/" ++ _, _} -> boss_simple_bridge_handler;
{"admin/" ++ _, _} -> nitrogen
end.
Then replace the calls in the above linked anchor module to:
application:get_env or simple_bridge_utils:get_env to routed_handler_mod(Req)
3) The last thing you'll probably need to do is to make sure to route
the requests to the new anchor module:
So while simple_bridge's cowboy supervisor creates a dispatch table
that looks like this:
[{'_',[],
[{[<<"js">>,'...'],
[],cowboy_static,
{dir,"./site/static/js/",[{mimetypes,cow_mimetypes,all}]}},
{[<<"css">>,'...'],
[],cowboy_static,
{dir,"./site/static/css/",[{mimetypes,cow_mimetypes,all}]}},
{[<<"images">>,'...'],
[],cowboy_static,
{dir,"./site/static/images/",[{mimetypes,cow_mimetypes,all}]}},
{[<<"nitrogen">>,'...'],
[],cowboy_static,
{dir,"./site/static/nitrogen/",[{mimetypes,cow_mimetypes,all}]}},
{[<<"favicon.ico">>],
[],cowboy_static,
{file,"./site/static/favicon.ico",[{mimetypes,cow_mimetypes,all}]}},
{'_',[],cowboy_simple_bridge_anchor,[]}]}]
You could modify just the last line of that to be:
{'_',[],my_custom_cowboy_simple_bridge_anchor,[]}]}]
It's a fair bit of work in a number of different areas, but the
alternative is just running a custom fork of simple_bridge that makes
those changes directly (which also isn't a terrible idea - Indeed that
gives me the idea of maybe allowing the "handler" module config to be
a function call).
As you plunk through this, be sure to keep us posted how you do or
what you get stuck on, because I find this to be an interesting idea,
and I'm very curious how it'll play out.
The alternative to all this, of course, is just spinning up two VMs
(one for CB and one for Nitrogen), and using nginx to route to each.
But as you said, you would like to avoid that.
-Jesse
> --
> You received this message because you are subscribed to the Google Groups
> "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
nitrogenweb...@googlegroups.com.
> To post to this group, send email to
nitro...@googlegroups.com.
> Visit this group at
https://groups.google.com/group/nitrogenweb.
> For more options, visit
https://groups.google.com/d/optout.
--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 ||
sigma-star.com || @jessegumm