Static files in an umbrella app containing a phoenix

Hi there!

I do have a (currently) small project. It is just an umbrella app, which contains a fresh phoenix project.

When I do start the app from the umbrellas root, I don’t get served static stuff, when I do start from within the phoenix folder, I do get served the static stuff as oe would expect.

It seems to work as expected though, when I ln -s apps/$PHOENIXAPP/priv priv in the umbrella project and then start from there.

But it feels wrong to copy/symlink stuff that belongs to the phoenix project into the umbrella, during further development I might need to have some priv-stuff in more than one project and would need to merge that as well.

So how can I configure the phoenix-app in a way that it works in the context of the umbrella without the necessity to copy/symlink anything?

3 Likes

I am uncertain if I am doing it right. I had the problem above, I think, and looking at commit history of my app, I sorted it out in the following way:

  1. I got rid of individual configs for the apps, in subdirectories. I just configure everything in the umbrella_root/config directory. I had to add this to my mix.exs in the children apps:

       build_path: "../../_build",
       config_path: "../../config/config.exs",
       deps_path: "../../deps",
       lockfile: "../../mix.lock",
    
  2. When I configure individual app (in the umbrella root), I explicitly set it’s config root to be dependent from the umbrella app:

     config :app, App.Endpoint,
        root: Path.dirname(__DIR__) <> "/apps/app",
        ...
    
  3. I still want my node_modules and static files folders in subdirectories of individual apps, so I had to configure the watchers in the same config section too:

      watchers: [node: ["node_modules/brunch/bin/brunch", "watch", "--stdin",
                 cd: Path.expand("../apps/app", __DIR__)]],
    

so that brunch command executes within subdirectories.

If you have multiple phoenix apps, you need to also specify different ports you want to start the on, or play with router/forward directive but I haven’t got my head around doing that just yet.

I think the steps above work for me, please let me know if it was any helpful :slight_smile:

2 Likes

I already considered configuring the children through the umbrella (which is okay, since it is the config of the umbrella which counts, as it uses the other apps as libraries in my understanding), but it feels wrong to alter the mix-file to point to common pathes.

I thought about umbrella children as applications that are bundled together and do know about each other as dependencies, but not about the enclosing umbrella.

If I need to tell the child, that it is part of an umbrella, I could smash everything together in a single app and just save me the work for proper separation.

So this brings me to the followup question, is my understanding of an umbrella app really this wrong and how could it be better?

1 Like

well the above is all the config part moved to umbrella app and we’re not actually changing the app itself, so I think it is in line with your thinking about it. I am unsure, however, if you can do that without amending mix.exs file to make it aware that it is part of the umbrella project.

Similarly, if you want to wrap it up into hex package you’d have to amend the mix.exs file as well.

1 Like