BeaconCMS / beacon

Open-source content management system (CMS) built with Phoenix LiveView. Faster render times to boost SEO performance, even for the most content-heavy pages.
https://beaconcms.org
MIT License
877 stars 89 forks source link

Has `Beacon.LiveAdmin.Router` moved / renamed #548

Closed camstuart closed 2 months ago

camstuart commented 2 months ago

Hi,

I can't seem to get past this step in a setup I am following now:

defmodule SaassleIOWeb.Router do
  use SaassleIOWeb, :router
  use Beacon.Router
  use Beacon.LiveAdmin.Router

Compiling 4 files (.ex) error: module Beacon.LiveAdmin.Router is not loaded and could not be found │ 4 │ use Beacon.LiveAdmin.Router │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ │ └─ lib/saassle_io_web/router.ex:4: SaassleIOWeb.Router (module)

However, use Beacon.Router is working fine, and I can access the default page:

scope "/articles" do
    pipe_through :browser
    beacon_site "/", site: :blog
  end

Without a problem. I cloned beacon itself, but can't find Beacon.LiveAdmin.Router or the def for beacon_live_admin Are these renamed perhaps?

leandrocp commented 2 months ago

Could you share how your router and mix.exs looks like?

camstuart commented 2 months ago

Could you share how your router and mix.exs looks like?

Sure:

I hope floki is not the problem, other deps won't allow me to modify the version

defmodule SaassleIO.MixProject do
  use Mix.Project

  @version "1.8.0"

  def project do
    [
      app: :saassle_io,
      version: @version,
      elixir: "~> 1.14",
      elixirc_paths: elixirc_paths(Mix.env()),
      start_permanent: Mix.env() == :prod,
      aliases: aliases(),
      deps: deps(),
      test_coverage: [tool: ExCoveralls],
      preferred_cli_env: [
        quality: :test,
        wallaby: :test,
        coveralls: :test,
        "coveralls.detail": :test,
        "coveralls.post": :test,
        "coveralls.html": :test,
        vcr: :test,
        "vcr.delete": :test,
        "vcr.check": :test,
        "vcr.show": :test
      ]
    ]
  end

  # Configuration for the OTP application.
  #
  # Type `mix help compile.app` for more information.
  def application do
    [
      mod: {SaassleIO.Application, []},
      extra_applications: [:logger, :runtime_tools]
    ]
  end

  # Specifies which paths to compile per environment.
  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_), do: ["lib"]

  # Specifies your project dependencies.
  #
  # Type `mix help deps` for examples and options.
  # Type `mix deps.update --all` to update deps (won't updated this file)
  # Type `mix hex.outdated` to see deps that can be updated
  defp deps do
    [
      # Phoenix base
      {:phoenix, "~> 1.7.3"},
      {:phoenix_ecto, "~> 4.4"},
      {:ecto_sql, "~> 3.10"},
      {:postgrex, ">= 0.0.0"},
      {:phoenix_html, "~> 4.0", override: true},
      {:phoenix_live_reload, "~> 1.2", only: :dev},
      {:phoenix_live_view, "~> 0.20"},
      {:floki, ">= 0.34.3"},
      # {:floki, ">= 0.30.0"},
      {:phoenix_live_dashboard, "~> 0.8"},
      {:esbuild, "~> 0.8", runtime: Mix.env() == :dev},
      {:swoosh, "~> 1.11"},
      {:telemetry_metrics, "~> 1.0"},
      {:telemetry_poller, "~> 1.0"},
      {:gettext, "~> 0.24", override: true},
      {:jason, "~> 1.2"},
      {:bandit, "~> 1.0"},
      {:dns_cluster, "~> 0.1.1"},
      {:beacon, github: "BeaconCMS/beacon", override: true},
      # {:poison, "~> 3.1.0"},

      # Emails
      {:phoenix_swoosh, "~> 1.0"},
      {:gen_smtp, "~> 1.2"},
      {:premailex, "~> 0.3.0"},

      # Ecto querying / pagination
      {:query_builder, "~> 1.0"},

      # Authentication
      {:bcrypt_elixir, "~> 3.0"},
      {:ueberauth, "<= 0.10.5 or ~> 0.10.7"},
      {:ueberauth_google, "~> 0.10"},
      {:ueberauth_github, "~> 0.7"},

      # API
      {:open_api_spex, "~> 3.18"},

      # TOTP (2FA)
      {:nimble_totp, "~> 1.0.0"},
      {:eqrcode, "~> 0.1.10"},

      # Hashing
      {:hashids, "~> 2.0"},

      # Assets
      {:tailwind, "~> 0.2.0", runtime: Mix.env() == :dev},

      # Petal components and framework
      {:petal_components, "~> 1.9"},
      {:petal_framework, "~> 0.8", repo: "petal"},

      # Utils
      {:blankable, "~> 1.0.0"},
      {:currency_formatter, "~> 0.4"},
      {:timex, "~> 3.7", override: true},
      {:inflex, "~> 2.1.0"},
      {:slugify, "~> 1.3"},
      {:sizeable, "~> 1.0"},

      # HTTP client
      {:tesla, "~> 1.8.0"},
      {:finch, "~> 0.14"},

      # Testing
      {:wallaby, "~> 0.30", runtime: false, only: :test},
      {:faker, "~> 0.17", only: [:test, :dev]},
      {:mimic, "~> 1.7", only: :test},
      {:exvcr, "~> 0.15", only: :test},

      # Jobs / Cron
      {:oban, "~> 2.17"},

      # Security
      {:content_security_policy, "~> 1.0"},

      # Code quality
      {:sobelow, "~> 0.12", only: [:dev, :test], runtime: false},
      {:credo, "~> 1.7", only: [:dev, :test], runtime: false},
      {:excoveralls, "~> 0.10", only: [:dev, :test], runtime: false},
      {:styler, "~> 0.11", only: [:dev, :test], runtime: false},

      # Payments
      {:stripity_stripe, "~> 3.1"}

      # Temporary (to rename your project)
      # {:rename_project, "~> 0.1.0", only: :dev, runtime: false}
    ]
  end

  # Aliases are shortcuts or tasks specific to the current project.
  # For example, to install project dependencies and perform other setup tasks, run:
  #
  #     $ mix setup
  #
  # See the documentation for `Mix` for more info on aliases.
  defp aliases do
    [
      setup: ["deps.get", "ecto.setup", "assets.setup", "assets.build"],
      "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
      "ecto.reset": ["ecto.drop", "ecto.setup"],
      test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"],
      "assets.setup": ["tailwind.install --if-missing", "esbuild.install --if-missing"],
      "assets.build": ["tailwind default", "esbuild default"],
      "assets.deploy": ["tailwind default --minify", "esbuild default --minify", "phx.digest"],
      # Run to check the quality of your code
      quality: [
        "format",
        "sobelow --config",
        "coveralls",
        "credo"
      ],
      update_translations: ["gettext.extract --merge"],

      # Unlocks unused dependencies (no longer mentioned in the mix.exs file)
      clean_mix_lock: ["deps.unlock --unused"],

      # Only run wallaby (e2e) tests
      wallaby: ["test --only feature"],
      seed: ["run priv/repo/seeds.exs"]
    ]
  end
end
defmodule SaassleIOWeb.Router do
  use SaassleIOWeb, :router
  use Beacon.Router
  # use Beacon.LiveAdmin.Router

  import SaassleIOWeb.OrgPlugs
  import SaassleIOWeb.SubscriptionPlugs
  import SaassleIOWeb.UserAuth
  import SaassleIOWeb.UserImpersonationController

  alias SaassleIOWeb.OnboardingPlug

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_live_flash
    plug :put_root_layout, {SaassleIOWeb.Layouts, :root}
    plug :protect_from_forgery

    # plug :put_secure_browser_headers, %{
    #   "content-security-policy" =>
    #     ContentSecurityPolicy.serialize(struct(ContentSecurityPolicy.Policy, SaassleIO.config(:content_security_policy)))
    # }
    plug :put_secure_browser_headers

    plug Beacon.LiveAdmin.Plug

    plug :fetch_current_user
    plug :fetch_impersonator_user
    plug :kick_user_if_suspended_or_deleted
    plug PetalFramework.SetLocalePlug, gettext: SaassleIOWeb.Gettext
  end

  pipeline :public_layout do
    plug :put_layout, html: {SaassleIOWeb.Layouts, :public}
  end

  pipeline :authenticated do
    plug :require_authenticated_user
    plug OnboardingPlug
    plug :assign_org_data
  end

  pipeline :subscribed_entity do
    plug :subscribed_entity_only
  end

  pipeline :subscribed_org do
    plug :subscribed_org_only
  end

  pipeline :subscribed_user do
    plug :subscribed_user_only
  end

  # Public routes
  scope "/", SaassleIOWeb do
    pipe_through [:browser, :public_layout]

    # Add public controller routes here
    get "/", PageController, :landing_page
    get "/privacy", PageController, :privacy
    get "/license", PageController, :license

    get "/terms-and-conditions/zendesk-apps", PageController, :zendesk_apps_terms_and_conditions
    get "/terms-and-conditions/zendesk-zis-hub", PageController, :zendesk_zis_hub_terms_and_conditions

    get "/contact", MessageController, :new
    post "/contact", MessageController, :create

    live_session :public, layout: {SaassleIOWeb.Layouts, :public} do
      # Add public live routes here
    end
  end

  # scope "/cms-admin" do
  #   pipe_through :browser
  #   beacon_live_admin("/")
  # end

  scope "/articles" do
    pipe_through :browser
    beacon_site "/", site: :blog
  end

  # App routes - for signed in and confirmed users only
  scope "/app", SaassleIOWeb do
    pipe_through [:browser, :authenticated]

    # Add controller authenticated routes here
    put "/users/settings/update-password", UserSettingsController, :update_password
    get "/users/settings/confirm-email/:token", UserSettingsController, :confirm_email
    get "/users/totp", UserTOTPController, :new
    post "/users/totp", UserTOTPController, :create

    live_session :authenticated,
      on_mount: [
        {SaassleIOWeb.UserOnMountHooks, :require_authenticated_user},
        {SaassleIOWeb.OrgOnMountHooks, :assign_org_data},
        {SaassleIOWeb.SubscriptionPlugs, :subscribed_entity}
      ] do
      # Add live authenticated routes here

      use SaassleIOWeb.BillingRoutes

      live "/", DashboardLive
      live "/users/onboarding", UserOnboardingLive
      live "/users/edit-profile", EditProfileLive
      live "/users/edit-email", EditEmailLive
      live "/users/change-password", EditPasswordLive
      live "/users/edit-notifications", EditNotificationsLive
      live "/users/org-invitations", UserOrgInvitationsLive
      live "/users/two-factor-authentication", EditTotpLive

      live "/orgs", OrgsLive, :index
      live "/orgs/new", OrgsLive, :new

      scope "/org/:org_slug" do
        live "/", OrgDashboardLive
        live "/edit", EditOrgLive
        live "/team", OrgTeamLive, :index
        live "/team/invite", OrgTeamLive, :invite
        live "/team/memberships/:id/edit", OrgTeamLive, :edit_membership
      end
    end
  end

  if SaassleIO.config(:impersonation_enabled?) do
    use SaassleIOWeb.AuthImpersonationRoutes
  end

  scope "/" do
    use SaassleIOWeb.AuthRoutes
    use SaassleIOWeb.SubscriptionRoutes
    use SaassleIOWeb.MailblusterRoutes
    use SaassleIOWeb.AdminRoutes
    use SaassleIOApi.Routes

    # DevRoutes must always be last
    use SaassleIOWeb.DevRoutes
  end
end
camstuart commented 2 months ago

A fresh phoenix project and beacon install seem to have the same problem

leandrocp commented 2 months ago

can't find Beacon.LiveAdmin.Router or the def for beacon_live_admin

Beacon.LiveAdmin.Router is available in https://github.com/BeaconCMS/beacon_live_admin so you'd need to install it first - just keep in mind that you can run admin as a separated project or in the same one as you're running beacon. To run in the same project you can skip to step 4 in that guide.

camstuart commented 2 months ago

can't find Beacon.LiveAdmin.Router or the def for beacon_live_admin

Beacon.LiveAdmin.Router is available in https://github.com/BeaconCMS/beacon_live_admin so you'd need to install it first - just keep in mind that you can run admin as a separated project or in the same one as you're running beacon. To run in the same project you can skip to step 4 in that guide.

Oh, I though the override: true was to bring that in, so I need another dependancy?

leandrocp commented 2 months ago

so I need another dependancy?

Yep.

override: true

That's required to run beacon and beacon_live_admin in the same project.

camstuart commented 2 months ago

Gotcha, thanks!