Umbrella project with multiple apps containing front end logic.
Asked Answered
H

1

6

I have 2 applications which have shared functionality/routes. For example, in both applications there is a diary, goal tracking, sleep tracking, etc which work in the same way. There are also routes specific to each app. In AppA, a user can track their mood, and in AppB a user can view notes from their doctor.

Is there a way to have an umbrella project which contains in /apps the generic app, AppA, and AppB? Each app will have it's own router/controllers/templates etc. AppA and AppB will each require the GenericApp as a dependency. So far I have only seen umbrella projects with one app that contains the front end logic (web), with the other apps being libraries that are included in. How can this work with routing across multiple apps? Is there another approach I can take for this?

I have found this question & answer in my search, however it is not exactly what I am looking for. It seems to follow the pattern of one front end app including in other libraries.

Hirsutism answered 31/7, 2017 at 10:6 Comment(0)
B
4

Yes, you can certainly split out the 'generic' routes into a separate umbrella app and forward to it from AppA and AppB.

Use the Phoenix.Router.forward/4 function to forward requests from AppA and AppB to the shared code.

For example, this is how the exq_ui can be incorporated into a larger application:

  pipeline :exq do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_flash
    plug :put_secure_browser_headers
    plug ExqUi.RouterPlug, namespace: "exq"
  end

  scope "/exq", ExqUi do
    pipe_through :exq
    forward "/", RouterPlug.Router, :index
  end
Bozen answered 31/7, 2017 at 12:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.