Skip to content

Commit

Permalink
feat: add verified routes
Browse files Browse the repository at this point in the history
  • Loading branch information
trueChazza committed Jul 21, 2023
1 parent e7ce157 commit 0338f63
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
17 changes: 17 additions & 0 deletions lib/media_server_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ defmodule MediaServerWeb do
and import those modules here.
"""

def static_paths, do: ~w(assets fonts images manifest browserconfig favicon logo android-icon apple-icon ms-icon)

def controller do
quote do
use Phoenix.Controller, namespace: MediaServerWeb

import Plug.Conn
import MediaServerWeb.Gettext

alias MediaServerWeb.Router.Helpers, as: Routes

unquote(verified_routes())
end
end

Expand Down Expand Up @@ -89,7 +94,19 @@ defmodule MediaServerWeb do

import MediaServerWeb.ErrorHelpers
import MediaServerWeb.Gettext

alias MediaServerWeb.Router.Helpers, as: Routes

unquote(verified_routes())
end
end

def verified_routes do
quote do
use Phoenix.VerifiedRoutes,
endpoint: MediaServerWeb.Endpoint,
router: MediaServerWeb.Router,
statics: MediaServerWeb.static_paths()
end
end

Expand Down
3 changes: 1 addition & 2 deletions lib/media_server_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ defmodule MediaServerWeb.Endpoint do
at: "/",
from: :media_server,
gzip: false,
only_matching:
~w(assets fonts images manifest browserconfig favicon logo android-icon apple-icon ms-icon)
only_matching: MediaServerWeb.static_paths()

# Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint.
Expand Down
2 changes: 2 additions & 0 deletions test/support/conn_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ defmodule MediaServerWeb.ConnCase do

using do
quote do
use MediaServerWeb, :verified_routes

# Import conveniences for testing with connections
import Plug.Conn
import Phoenix.ConnTest
Expand Down

0 comments on commit 0338f63

Please sign in to comment.