### defaults() Source: https://hexdocs.pm/cors_plug/CORSPlug.html Returns the default configuration settings for CORSPlug. ```APIDOC ## defaults() ### Description Returns the default configuration settings for CORSPlug. ### Function Signature defaults() ### Returns - `map`: A map containing the default CORSPlug settings. ``` -------------------------------- ### Configure Origin with a Function/1 Source: https://hexdocs.pm/cors_plug/index.html Use a function/1 that accepts the connection and returns the allowed origin. Anonymous functions are not supported. ```elixir plug CORSPlug, origin: &MyModule.my_fun/1 def my_fun(conn) do # Do something with conn ["http://example.com"] end ``` -------------------------------- ### Configure Origin with a Function/0 Source: https://hexdocs.pm/cors_plug/index.html Use a function/0 to dynamically determine the allowed origin. Anonymous functions are not supported. ```elixir plug CORSPlug, origin: &MyModule.my_fun/0 def my_fun do ["http://example.com"] end ``` -------------------------------- ### Configure CORSPlug via config.exs Source: https://hexdocs.pm/cors_plug/index.html Set CORSPlug configuration options, such as origin, max_age, and methods, in your config.exs file. ```elixir config :cors_plug, origin: ["http://example.com"], max_age: 86400, methods: ["GET", "POST"] ``` -------------------------------- ### Configure Endpoint in Phoenix Source: https://hexdocs.pm/cors_plug/index.html Recommended placement for CORSPlug in lib/your_app/endpoint.ex for Phoenix Framework applications. This ensures it's applied to all matched routes. ```elixir defmodule YourApp.Endpoint do use Phoenix.Endpoint, otp_app: :your_app # ... plug CORSPlug plug YourApp.Router end ``` -------------------------------- ### Configure Allowed Origins with a List Source: https://hexdocs.pm/cors_plug/index.html Configure the allowed origins for CORSPlug using a list that can contain strings or regular expressions. ```elixir plug CORSPlug, origin: ["http://example1.com", "http://example2.com", ~r/https?.*example\d?\.com$/] ``` -------------------------------- ### License Information Source: https://hexdocs.pm/cors_plug/index.html Copyright and licensing information for the CorsPlug. ```text http://www.apache.org/licenses/LICENSE-2.0 ``` -------------------------------- ### Add CorsPlug Dependency Source: https://hexdocs.pm/cors_plug/index.html Add the cors_plug dependency to your mix.exs file to include it in your project. ```elixir def deps do # ... {:cors_plug, "~> 3.0"}, #... end ``` -------------------------------- ### Configure Allowed Origins with a Regex Source: https://hexdocs.pm/cors_plug/index.html Configure the allowed origins for CORSPlug using a single regular expression. ```elixir plug CORSPlug, origin: ~r/https?.*example\d?\.com$/ ``` -------------------------------- ### Configure Pipeline in Phoenix Router Source: https://hexdocs.pm/cors_plug/index.html Alternative configuration for CORSPlug within a pipeline in the Phoenix router, typically used for API scopes. ```elixir pipeline :api do plug CORSPlug # ... end scope "/api", PhoenixApp do pipe_through :api resources "/articles", ArticleController options "/articles", ArticleController, :options options "/articles/:id", ArticleController, :options end ``` -------------------------------- ### Disable Preflight Response Source: https://hexdocs.pm/cors_plug/index.html Set `send_preflight_response?: false` to have CORSPlug only set headers for OPTIONS requests, retaining control over the response. ```elixir plug CORSPlug, send_preflight_response?: false # or in the app config config :cors_plug, send_preflight_response?: false ``` -------------------------------- ### origins_match?(req_origin, origin) Source: https://hexdocs.pm/cors_plug/CORSPlug.html Determines if a request origin matches a specified origin pattern. ```APIDOC ## origins_match?(req_origin, origin) ### Description Determines if a request origin matches a specified origin pattern. This function handles wildcard matching for origins. ### Function Signature origins_match?(req_origin, origin) ### Parameters - **req_origin** (string) - The origin of the incoming request. - **origin** (string) - The origin pattern to match against. ### Returns - `boolean`: `true` if the request origin matches the pattern, `false` otherwise. ``` -------------------------------- ### origin_in_list?(req_origin, origins) Source: https://hexdocs.pm/cors_plug/CORSPlug.html Checks if a given request origin is present in a list of allowed origins. ```APIDOC ## origin_in_list?(req_origin, origins) ### Description Checks if a given request origin is present in a list of allowed origins. ### Function Signature origin_in_list?(req_origin, origins) ### Parameters - **req_origin** (string) - The origin of the incoming request. - **origins** (list of string or map) - A list of allowed origins or a map defining origins. ### Returns - `boolean`: `true` if the request origin is found in the list, `false` otherwise. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.