Skip to content

Commit

Permalink
chore: remove route /css_config (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrocp authored Nov 20, 2024
1 parent 94f42fc commit f91a3b3
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 34 deletions.
3 changes: 0 additions & 3 deletions lib/beacon/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ defmodule Beacon.Router do
live_session session_name, session_opts do
get "/__beacon_media__/:file_name", Beacon.Web.MediaLibraryController, :show, assigns: %{site: opts[:site]}

# TODO: css_config-:md5 caching
get "/__beacon_assets__/css_config", Beacon.Web.AssetsController, :css_config, assigns: %{site: opts[:site]}

get "/__beacon_assets__/css-:md5", Beacon.Web.AssetsController, :css, assigns: %{site: opts[:site]}
get "/__beacon_assets__/js-:md5", Beacon.Web.AssetsController, :js, assigns: %{site: opts[:site]}

Expand Down
10 changes: 0 additions & 10 deletions lib/beacon/runtime_css.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ defmodule Beacon.RuntimeCSS do
Beacon.Config.fetch!(site).css_compiler.config(site)
end

@doc """
Returns the URL to fetch the CSS config used to generate the site stylesheet.
"""
@spec asset_url(Site.t()) :: String.t()
def asset_url(site) do
%{endpoint: endpoint, router: router} = Beacon.Config.fetch!(site)
prefix = router.__beacon_scoped_prefix_for_site__(site)
endpoint.url() <> Beacon.Router.sanitize_path("#{prefix}/__beacon_assets__/css_config")
end

@doc false
def compile(site) when is_atom(site) do
Beacon.Config.fetch!(site).css_compiler.compile(site)
Expand Down
22 changes: 1 addition & 21 deletions lib/beacon/web/controllers/assets_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Beacon.Web.AssetsController do

import Plug.Conn

def init(asset) when asset in [:css_config, :css, :js], do: asset
def init(asset) when asset in [:css, :js], do: asset

def call(%{assigns: %{site: site}} = conn, asset) when asset in [:css, :js] do
{content, content_type} = content_and_type(site, asset)
Expand All @@ -22,31 +22,11 @@ defmodule Beacon.Web.AssetsController do
|> halt()
end

# TODO: encoding (compress) and caching
def call(%{assigns: %{site: site}} = conn, :css_config) do
{content, content_type} = content_and_type(site, :css_config)

# The static files are served for sites,
# and we need to disable csrf protection because
# serving script files is forbidden by the CSRFProtection plug.
conn = put_private(conn, :plug_skip_csrf_protection, true)

conn
|> put_resp_header("content-type", content_type)
|> put_resp_header("access-control-allow-origin", "*")
|> send_resp(200, content)
|> halt()
end

defp content_and_type(site, :css) do
{Beacon.RuntimeCSS.fetch(site), "text/css"}
end

defp content_and_type(_site, :js) do
{Beacon.RuntimeJS.fetch(), "text/javascript"}
end

defp content_and_type(site, :css_config) do
{Beacon.RuntimeCSS.config(site), "text/javascript"}
end
end

0 comments on commit f91a3b3

Please sign in to comment.