elixir-crawly / crawly

Crawly, a high-level web crawling & scraping framework for Elixir.
https://hexdocs.pm/crawly
Apache License 2.0
953 stars 112 forks source link

Encountering Complications with Forwarding to Crawly.API.Router #275

Closed oallanmendes closed 3 months ago

oallanmendes commented 8 months ago

Hello everyone,

First and foremost, I want to express my appreciation for this project. I've been testing it out and have been really enjoying it. However, I've encountered an issue. I followed the introduction instructions, but I'm having trouble rendering the Simple Management UI.

I added the line forward "/admin", Crawly.API.Router, but I can't seem to add use Plug.Router. When I include the second line, the project fails to compile and throws the following error:

error: function plug/2 imported from both Plug.Builder and Phoenix.Router, call is ambiguous
  lib/hello_web/router.ex:6: HelloWeb.Router (module)

== Compilation error in file lib/hello_web/router.ex ==
** (CompileError) lib/hello_web/router.ex: cannot compile module HelloWeb.Router (errors have been logged)
    (phoenix 1.7.10) expanding macro: Phoenix.Router.pipeline/2
    lib/hello_web/router.ex:5: HelloWeb.Router (module)
:error

Do I need to include use Plug.Router for it to work? Is resolving this compilation error a prerequisite for accessing the Simple Management UI? Could someone kindly assist me in identifying the issue?

Mix.ex file provided below:

defmodule Hello.MixProject do
  use Mix.Project

  def project do
    [
      app: :hello,
      version: "0.1.0",
      elixir: "~> 1.14",
      elixirc_paths: elixirc_paths(Mix.env()),
      start_permanent: Mix.env() == :prod,
      aliases: aliases(),
      deps: deps()
    ]
  end

  # Configuration for the OTP application.
  #
  # Type `mix help compile.app` for more information.
  def application do
    [
      mod: {Hello.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.
  defp deps do
    [
      {:phoenix, "~> 1.7.9"},
      {:phoenix_ecto, "~> 4.4"},
      {:ecto_sql, "~> 3.10"},
      {:postgrex, ">= 0.0.0"},
      {:phoenix_html, "~> 3.3"},
      {:phoenix_live_reload, "~> 1.2", only: :dev},
      {:phoenix_live_view, "~> 0.20.1"},
      {:phoenix_live_dashboard, "~> 0.8.2"},
      {:esbuild, "~> 0.7", runtime: Mix.env() == :dev},
      {:tailwind, "~> 0.2.0", runtime: Mix.env() == :dev},
      {:swoosh, "~> 1.3"},
      {:finch, "~> 0.13"},
      {:telemetry_metrics, "~> 0.6"},
      {:telemetry_poller, "~> 1.0"},
      {:gettext, "~> 0.20"},
      {:jason, "~> 1.2"},
      {:dns_cluster, "~> 0.1.1"},
      {:plug_cowboy, "~> 2.5"},
      {:crawly, "~> 0.16.0"},
      {:floki, "~> 0.33.0"}
    ]
  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"]
    ]
  end
end
kasvith commented 6 months ago

@oallanmendes

you need to scope it like this

  scope "/admin" do
    pipe_through :browser

    forward "/", Crawly.API.Router
  end