elixir-maru / maru

Elixir RESTful Framework
https://maru.readme.io
BSD 3-Clause "New" or "Revised" License
1.32k stars 85 forks source link

Problems with multiple Maru apps in one umbrella project #64

Closed OiNutter closed 7 years ago

OiNutter commented 7 years ago

I'm not sure if this is just a undocumented config setting or an actual bug but I'm having problems with several Maru apps in one umbrella project. I'm building a REST api as an umbrella project so I can seperate out the components into microservices. Before I added Maru to provide the routing for each module I was able to run tests either as a whole or for each individual app. Once I've added Maru I now can't start one of the apps by itself unless it has the others as a dependecy, because it tries to start the Maru routers for all sub apps, rather than just the one I'm in, which obviously it can't find.

falood commented 7 years ago

Hi @OiNutter , I never try multiple maru apps in umbrella project, will test it myself and give a response soon, thanks.

falood commented 7 years ago

Hi @OiNutter Sorry for the delay, I worked on other stuff these days. I tried multiple maru apps in umbrella and did an example https://github.com/elixir-maru/maru_examples/tree/master/maru_umbrella , I think everything works well. For the unittest issue, I guess that's because unittest in maru v0.11 doesn't works well, I refactor the unit test, can you have a try with maru v0.12? let me know if you have other issue 🙂

OiNutter commented 7 years ago

Hi @falood

It doesn't seem to work as I'd expect when I try your example. Maybe it's just my misunderstanding but when I run iex -S mix in on of the app folders, I would expect it to only try and start that particular app. At the moment I get the following error if I run that command in the my_api folder;

** (Mix) Could not start application maru: Maru.start(:normal, []) returned an error: an exception was raised:
** (UndefinedFunctionError) function MyAPI2.API.init/1 is undefined (module MyAPI2.API is not available)
    MyAPI2.API.init([])
    (plug) lib/plug/adapters/cowboy.ex:271: Plug.Adapters.Cowboy.dispatch_for/2
    (plug) lib/plug/adapters/cowboy.ex:51: Plug.Adapters.Cowboy.args/4
    (plug) lib/plug/adapters/cowboy.ex:144: Plug.Adapters.Cowboy.child_spec/4
    (maru) lib/supervisor.ex:18: anonymous fn/4 in Maru.Supervisor.init/1
    (elixir) lib/enum.ex:1755: Enum."-reduce/3-lists^foldl/2-0-"/3
    (maru) lib/supervisor.ex:16: anonymous fn/2 in Maru.Supervisor.init/1
    (elixir) lib/enum.ex:1755: Enum."-reduce/3-lists^foldl/2-0-"/3

I'm running elixir 1.4.0 if that makes any difference

falood commented 7 years ago

@OiNutter I see, because the config is shared between apps. I'll make it put some log instead of crash the application.

OiNutter commented 7 years ago

Awesome, that does the trick, thanks!