plug_canonical_host alternatives and similar packages
Based on the "Framework Components" category.
Alternatively, view plug_canonical_host alternatives based on common mentions on social networks and blogs.
-
commanded
Use Commanded to build Elixir CQRS/ES applications -
surface
A server-side rendering component library for Phoenix -
ex_admin
ExAdmin is an auto administration package for Elixir and the Phoenix Framework -
phoenix_html
Phoenix.HTML functions for working with HTML strings and templates -
phoenix_ecto
Phoenix and Ecto integration with support for concurrent acceptance testing -
absinthe_plug
Plug support for Absinthe, the GraphQL toolkit for Elixir -
react_phoenix
Make rendering React.js components in Phoenix easy -
phoenix_live_reload
Provides live-reload functionality for Phoenix -
params
Easy parameters validation/casting with Ecto.Schema, akin to Rails' strong parameters. -
dayron
A repository `similar` to Ecto.Repo that maps to an underlying http client, sending requests to an external rest api instead of a database -
phoenix_pubsub_redis
The Redis PubSub adapter for the Phoenix framework -
rummage_ecto
Search, Sort and Pagination for ecto queries -
phoenix_token_auth
Token authentication solution for Phoenix. Useful for APIs for e.g. single page apps. -
rummage_phoenix
Full Phoenix Support for Rummage. It can be used for searching, sorting and paginating collections in phoenix. -
recaptcha
A simple reCaptcha 2 library for Elixir applications. -
plug_graphql
Plug (Phoenix) integration for GraphQL Elixir -
sentinel
DEPRECATED - Phoenix Authentication library that wraps Guardian for extra functionality -
plug_rails_cookie_session_store
Rails compatible Plug session store -
multiverse
Elixir package that allows to add compatibility layers via API gateways. -
access pass
provides a full user authentication experience for an API. Includes login,logout,register,forgot password, forgot username, confirmation email and all that other good stuff. Includes plug for checking for authenticated users and macro for generating the required routes. -
phx_component_helpers
Extensible Phoenix liveview components, without boilerplate -
filterable
Filtering from incoming params in Elixir/Ecto/Phoenix with easy to use DSL. -
scrivener_headers
Scrivener pagination with headers and web linking -
better_params
Cleaner request parameters in Elixir web applications 🙌 -
phoenix_pubsub_rabbitmq
RabbitMQ adapter for Phoenix's PubSub layer -
plug_checkup
PlugCheckup provides a Plug for adding simple health checks to your app -
plug_statsd
Send connection response time and count to statsd -
plug_rest
REST behaviour and Plug router for hypermedia web applications in Elixir -
trailing_format_plug
An elixir plug to support legacy APIs that use a rails-like trailing format: http://api.dev/resources.json -
phoenix_html_simplified_helpers
Some helpers for phoenix html( truncate, time_ago_in_words, number_with_delimiter, url_for, current_page? ) -
Votex
Implements vote / like / follow functionality for Ecto models in Elixir. Inspired from Acts as Votable gem in Ruby on Rails
Bot detection and prevention for Elixir/Phoenix applications
Do you think we are missing an alternative of plug_canonical_host or a related project?
Popular Comparisons
README
PlugCanonicalHost ensures that all requests are served by a single canonical host. It will redirect all requests from non-canonical hosts to the canonical one.
Installation
Add plug_canonical_host
to the deps
function in your project’s mix.exs
file:
defp deps do
[
…,
{:plug_canonical_host, "~> 2.0"}
]
end
Then run mix do deps.get, deps.compile
inside your project’s directory.
Usage
PlugCanonicalHost
can be used just as any other plugs. Add PlugCanonicalHost
before all of the other plugs you want to happen after successful redirect to your canonical host.
The recommended way to define a canonical host is with an environment variable.
# config/releases.exs
config :my_app,
canonical_host: System.get_env("CANONICAL_HOST")
# lib/my_app/endpoint.ex
defmodule MyApp.Endpoint do
plug(:canonical_host)
defp canonical_host(conn, _opts) do
:my_app
|> Application.get_env(:canonical_host)
|> case do
host when is_binary(host) ->
opts = PlugCanonicalHost.init(canonical_host: host)
PlugCanonicalHost.call(conn, opts)
_ ->
conn
end
end
end
For example, if your CANONICAL_HOST
is www.example.com
but your application is accessible via both example.com
and www.example.com
, all traffic coming through example.com
will be redirected (with a 301
HTTP status) to the matching www.example.com
URL.
$ curl -sI "http://example.com/foo?bar=1"
#> HTTP/1.1 301 Moved Permanently
#> Location: http://www.example.com/foo?bar=1
If you want to exclude certain requests from redirecting to the canonical host, you can use simple pattern matching in your function arguments:
defmodule MyApp.Endpoint do
plug(:canonical_host)
defp canonical_host(%Plug.Conn{request_path: "/ignore-me"} = conn, _opts) do
Plug.Conn.send_resp(conn, 200, "👋")
end
defp canonical_host(conn, _opts) do
:my_app
|> Application.get_env(:canonical_host)
|> case do
host when is_binary(host) ->
opts = PlugCanonicalHost.init(canonical_host: host)
PlugCanonicalHost.call(conn, opts)
_ ->
conn
end
end
end
Now, all requests going to the /ignore-me
path will skip the canonical host redirect behavior.
$ curl -sI "http://example.com/foo?bar=1"
#> HTTP/1.1 301 Moved Permanently
#> Location: http://www.example.com/foo?bar=1
$ curl -sI "http://example.com/ignore-me"
#> HTTP/1.1 200 OK
License
PlugCanonicalHost
is © 2016-2020 Rémi Prévost and may be freely distributed under the MIT license. See the LICENSE.md
file for more information.
The plug logo is based on this lovely icon by Vectors Market, from The Noun Project. Used under a Creative Commons BY 3.0 license.
*Note that all licence references and agreements mentioned in the plug_canonical_host README section above
are relevant to that project's source code only.