Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal assets aren't being found even that they exist #324

Closed
zoedsoupe opened this issue Jul 25, 2023 · 5 comments
Closed

Internal assets aren't being found even that they exist #324

zoedsoupe opened this issue Jul 25, 2023 · 5 comments
Assignees
Labels
question Further information is requested

Comments

@zoedsoupe
Copy link

I have an umbrella app which has many web apps of different domains. However, I would like to extract common components and styles to a separate application called :design_system.

To correctly forward and handle different paths request I also have a :proxy_web app that forwards to the respective endpoint based on the conn.path_info pattern.

Here's the ProxyWeb main part, the router:

defmodule ProxyWeb.Router do
  @behaviour Plug

  def init(opts), do: opts

  def call(conn, _opts) do
    endpoint = forward_conn(conn.path_info)
    endpoint.call(conn, [])
  end

  defp forward_conn(["api" | _]), do: PlataformaDigitalAPI.Endpoint
  defp forward_conn(["design-system" | _]), do: DesignSystem.Endpoint
  defp forward_conn(_), do: PlataformaDigital.Endpoint
end

Thats works fine, but phoenix_storybook has a strange behaviour.

In my :design_system app I define the router as:

defmodule DesignSystem.Router do
  use Phoenix.Router, helpers: false

  import PhoenixStorybook.Router

  scope "/" do
    storybook_assets("/design-system/storybook/assets")

    live_storybook("/design-system/storybook",
      backend_module: DesignSystem.Storybook,
      assets_path: "/design-system/storybook/assets"
    )
  end
end

So now I'm able to reach /design-system/storybook/assets/css/app.css for example, in the browser!

However, when I reach to /design-system/storybook the page reloads infinitely because the conn is halted on the AssetNotFoundController of phoenix_storybook

The partial log is

[debug] compiling storybook file: typography.story.exs
[debug] Processing with PhoenixStorybook.AssetNotFoundController.asset/2
  Parameters: %{"asset" => ["css", "fonts.css"]}
  Pipelines: [:storybook_assets]
[debug] Phoenix.Router halted in :storybook_assets/2
[debug] Processing with PhoenixStorybook.AssetNotFoundController.asset/2
  Parameters: %{"asset" => ["css", "app.css"]}
  Pipelines: [:storybook_assets]
[debug] Processing with PhoenixStorybook.AssetNotFoundController.asset/2
  Parameters: %{"asset" => ["js", "app.js"]}
  Pipelines: [:storybook_assets]
[debug] Phoenix.Router halted in :storybook_assets/2
[debug] Phoenix.Router halted in :storybook_assets/2

Sample Video

Screen.Recording.2023-07-25.at.18.09.02.mov

The complete source code can be found at https://github.com/peapescarte/pescarte-plataforma/tree/feat/design-system-app

@cblavier
Copy link
Contributor

cblavier commented Oct 7, 2023

hey Zoey, sorry I hadn't much time lately to work on the storybook, but I'm now tackling all open issues.
Is your issue still relevant? If so, I can help this week

@zoedsoupe
Copy link
Author

yes, it is!

@cblavier
Copy link
Contributor

Ok, I’ll try to reproduce your error tomorrow!

@cblavier cblavier self-assigned this Oct 11, 2023
@cblavier
Copy link
Contributor

Hey Zoey, it took me a couple of hours to dig down to the issue, but the problem was you are not providing the storybook a LiveView endpoint.

I fixed it with:

diff --git a/apps/design_system/lib/design_system/endpoint.ex b/apps/design_system/lib/design_system/endpoint.ex
index 07356ee..62a1513 100644
--- a/apps/design_system/lib/design_system/endpoint.ex
+++ b/apps/design_system/lib/design_system/endpoint.ex
@@ -12,5 +12,7 @@ defmodule DesignSystem.Endpoint do
     key: "_design_system_key",
     signing_salt: "OBcQb8Zm"
 
+  socket("/design-system/live", Phoenix.LiveView.Socket)
+
   plug DesignSystem.Router
 end
diff --git a/apps/design_system/lib/design_system/router.ex b/apps/design_system/lib/design_system/router.ex
index 7bcca04..f404532 100644
--- a/apps/design_system/lib/design_system/router.ex
+++ b/apps/design_system/lib/design_system/router.ex
@@ -8,7 +8,8 @@ defmodule DesignSystem.Router do
 
     live_storybook("/design-system/storybook",
       backend_module: DesignSystem.Storybook,
-      assets_path: "/design-system/storybook/assets"
+      assets_path: "/design-system/storybook/assets",
+      live_socket_path: "/design-system/live"
     )
   end
 end

Let me know if it's working for you!

@cblavier cblavier added the question Further information is requested label Oct 11, 2023
@cblavier
Copy link
Contributor

I'm closing, feel free to re-open if you are still stuck with this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants