Is there a good way to embed a phoenix app to another phoenix app?

Here’s the sample example.

json_corp_web embeds test_api.

HTML page shows well.

https://json.media/test_api

But js, CSS of json-corp(not test_api) is loaded on that page.

I have no idea how to use js, CSS of embedded phoenix application.

I want to embed many small projects in one root project to operate them on one fly.io machine easily, and split them for each machine when some projects grow up.

I succeeded in it.

It would be useful for others if you posted the solution here.

4 Likes

Nicd is right, I’ve been curious about how to do this. Maybe I could follow your breadcrumbs from the other thread but it would be great if this was broken down explicitly for others like me.

The commits below are the way I do this. I’m gonna write a post about this, but there are still some problems that should be solved yet(ex. merging package.json).

2 Likes

Also you if you want to embed the styles off the child app:

  • In childapp/config.exs add this
    version: "3.3.2",
    ratchet: [
      args: ~w(
        --config=../../childapp/assets/tailwind.config.js # This should point to your child app
        --input=../../childapp/assets/css/app.css # This should point to your child app
        --outdir=../priv/static/assets
      ),
      cd: Path.expand("../../../ratchet/assets", __DIR__),
      env: %{"NODE_PATH" => Path.expand("../../deps", __DIR__)}
    ]
    

*  Then build assets:

 "assets.deploy": ["tailwind default --minify", "esbuild default --minify", "tailwind ratchet --minify", "esbuild childapp --minify",  "esbuild ratchet --minify", "phx.digest"]

Hope this thing can additionally help somebody. It took me a while to get it right the first time!