honungsburk
Hi!
I’m building a small internal service to handle emails (it is not a webserver) and for this I have choosen Swoosh. Now I am trying to setup the mailbox preview and I want to use as few dependencies and as minimal setup as possible. Idealy, I would not even need to include it in the production environment but only in dev. What is hte minimal setup to make the preview work? Do I need to use pheonix as a dependency or is plug enough?
This is what I am currently trying:
config:
config :muninn, Phoenix.Endpoint,
url: [host: "localhost"],
render_errors: [formats: [html: Phoenix.Template.HTML]],
pubsub_server: Muninn.PubSub,
adapter: Bandit.PhoenixAdapter,
live_view: [signing_salt: "some_salt"]
application:
defmodule Muninn.Application do
@moduledoc """
Application module for Muninn.
"""
use Application
require Logger
@impl true
def start(_type, _args) do
# Oban.Telemetry.attach_default_logger(
# level: Application.get_env(:logger, :level),
# encode: true
# )
children = [
Muninn.Repo,
{Oban, Application.fetch_env!(:muninn, Oban)}
]
children =
if Application.get_env(:muninn, :email_preview) do
# children ++ [{Phoenix.Endpoint, []}]
children ++
[
# {Plug.Cowboy, scheme: :http, plug: Muninn.Router, options: [port: 4000]}
{Phoenix.PubSub, name: Muninn.PubSub},
# Start to serve requests, typically the last entry
Muninn.Endpoint
]
end
Supervisor.start_link(children, strategy: :one_for_one)
end
# Tell Phoenix to update the endpoint configuration
# whenever the application is updated.
@impl true
def config_change(changed, _new, removed) do
Muninn.Endpoint.config_change(changed, removed)
:ok
end
end
Endpoint:
defmodule Muninn.Endpoint do
use Phoenix.Endpoint, otp_app: :runar
# 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: "_muninn_key",
signing_salt: "C6nzbDmG",
same_site: "Lax"
]
socket("/live", Phoenix.LiveView.Socket,
websocket: [connect_info: [:peer_data, session: @session_options]],
longpoll: [connect_info: [:peer_data, 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: :muninn,
gzip: false,
only: ~w(assets fonts images favicon.ico robots.txt manifest.json)
)
# Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint.
if code_reloading? do
socket("/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket)
plug(Phoenix.LiveReloader)
plug(Phoenix.CodeReloader)
# plug(Phoenix.Ecto.CheckRepoStatus, otp_app: :muninn)
end
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(Muninn.Router)
end
router file:
defmodule Muninn.Router do
use Phoenix.Router
import Plug.Conn
import Phoenix.Controller
import Phoenix.LiveReloader
pipeline :browser do
plug(:accepts, ["html"])
plug(:fetch_session)
if Mix.env() == :dev do
plug(:fetch_live_reload)
end
end
scope "/dev" do
pipe_through(:browser)
forward("/mailbox", Plug.Swoosh.MailboxPreview,
csp_nonce_assign_key: %{script: :script_csp_nonce, style: :style_csp_nonce}
)
end
end
But I’m getting this error:
error: undefined function fetch_live_reload/2 (expected Muninn.Router to define such a function or for it to be imported, but none are available)
└─ deps/phoenix/lib/phoenix/router.ex: Muninn.Router.browser/2
```
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
honungsburk
Got it working by following the instructions in the README: GitHub - swoosh/swoosh: Compose, deliver and test your emails easily in Elixir · GitHub