sreyansjain

sreyansjain

Hologram: unable to make router work

Hi
I am trying to create a new app using hologram.

Erlang version: OTP 27
Elixir 1.18.0

I start with

mix phx.new insta --no-html --no-live --no-ecto

Then i follow the steps mentioned in the installation page

Then I create a folder call app/pages under the root folder insta
I add a home.ex file in the insta/app/pages folder

The file is -

defmodule Insta.HomePage do
  use Hologram.Page
  # alias Blog.Components.PostPreview
  
  route "/"
  
  # layout Blog.MainLayout
  
  def init(_params, component, _server) do
    posts = [
      %{id: 1, title: "First Post", excerpt: "This is my first post"},
      %{id: 2, title: "Second Post", excerpt: "Another great post"}
    ]
    
    put_state(component, :posts, posts)
  end

  def template do
    ~H"""
    <h1>Welcome to my Blog</h1>
    
    <div class="posts">
      {%for post <- @posts}
        <p>{post.title}</p>
      {/for}
    </div>
    """
  end
end

The app compiles fine, but I am not able to get anything on the route.
When i do mix holo.routes I get this -

07:35:46.980 [info] Hologram: compiler finished
--------------------------------------------------------------------------------
ROUTE / MODULE / SOURCE FILE
--------------------------------------------------------------------------------

Below is my endpoint file

defmodule InstaWeb.Endpoint do
  use Phoenix.Endpoint, otp_app: :insta
  use Hologram.Endpoint

  # The session will be stored in the cookie and signed,
  # this means its contents can be read but not tampered with.
  # Set :encryption_salt if you would also like to encrypt it.
  @session_options [
    store: :cookie,
    key: "_insta_key",
    signing_salt: "bvfPrVAO",
    same_site: "Lax"
  ]

  hologram_socket()

  # socket "/live", Phoenix.LiveView.Socket,
  #   websocket: [connect_info: [session: @session_options]],
  #   longpoll: [connect_info: [session: @session_options]]

  # Serve at "/" the static files from "priv/static" directory.
  #
  # You should set gzip to true if you are running phx.digest
  # when deploying your static files in production.
  plug Plug.Static,
    at: "/",
    from: :insta,
    gzip: false,
    only: ["hologram" | InstaWeb.static_paths()]

  # Code reloading can be explicitly enabled under the
  # :code_reloader configuration of your endpoint.
  if code_reloading? do
    plug Phoenix.CodeReloader
  end

  plug Phoenix.LiveDashboard.RequestLogger,
    param_key: "request_logger",
    cookie_key: "request_logger"

  plug Plug.RequestId
  plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]

  plug Plug.Parsers,
    parsers: [:urlencoded, :multipart, :json],
    pass: ["*/*"],
    json_decoder: Phoenix.json_library()

  plug Plug.MethodOverride
  plug Plug.Head
  plug Plug.Session, @session_options
  plug Hologram.Router
  # plug InstaWeb.Router
end

Please advise.

Marked As Solved

bartblast

bartblast

Creator of Hologram

Thanks, the problem is that you added your app dir outside the lib dir. If you want it to work that way you need to add the app dir to Elixir compile paths:

in your mix.exs:

defp elixirc_paths(:test), do: ["app", "lib", "test/support"]
defp elixirc_paths(_), do: ["app", "lib"]

Also Liked

Eiji

Eiji

Looks like you forgot to add something to your app. Please make sure that you follow installation instructions especially the parts of endpoint and router:
https://hologram.page/docs/installation

bartblast

bartblast

Creator of Hologram

Hey @sreyansjain,
I noticed that the layout module is commented out in your page. This is required. Hologram will raise a compilation error if a page doesn’t have a layout specified - is this the actual code you use?
The layout needs to include the Hologram.UI.Runtime component which handles rendering the runtime and page JS bundles. Without the Runtime component, your page won’t be properly initialized.

sreyansjain

sreyansjain

Its just a new phoenix project with nothing in it except what should go in for hologram.

mix phx.new insta --no-html --no-live --no-ecto

You can download here

sreyansjain

sreyansjain

I rechecked. I think I have followed the steps mentioned. There’s no error on compiling.

sreyansjain

sreyansjain

Works. Actually I saw the app folder in the hologram/test/features project so i thought code needs to go in the app folder, but overlooked the paths.

Thank you so much for your time.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement