codomari · landing · page · index · chatgpt

Codomari #4 (landing page)

For current state of project development our landing page will be simple.

To not waste time with designing page using html + css I decided to ask ChatGPT to generate it for me.

chatgpt landing page

As result we have got simple enough landing page which is OK for now.

landing page


Now we need to serve it.

Let’s save it in priv/static/index.html and serve it using such handler:

File lib/codomari_backend/handlers/public/index_page_handler.ex

defmodule CodomariBackend.Handlers.Public.IndexPageHandler do
  use CodomariBackend, :controller

  def handle(conn, _params) do
    index_file = Path.join(:code.priv_dir(:codomari_backend), "/static/index.html")

    conn
    |> put_resp_content_type("text/html")
    |> send_file(200, index_file)
  end
end

and do not forget to attach handler to in router: lib/codomari_backend/router/router.ex

defmodule CodomariBackend.Router do
  use CodomariBackend, :router

  alias Handlers.Public.IndexPageHandler, as: IndexPageHandler

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :put_root_layout, html: {CodomariBackend.Layouts, :root}
    plug :protect_from_forgery
    plug :put_secure_browser_headers
  end

  scope "/", CodomariBackend do
    pipe_through :browser

    get "/", IndexPageHandler, :handle  #  <= THIS ONE
  end
end

In next post I’m going to add api route to serve information about system (name, version and etc.).


Don’t forget to check repo: https://github.com/num8er/codomari-backend


Talk Soon!