Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: change cors library from corsica to cors_plug #368

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export AWS_SECRET_ACCESS_KEY=[YOUR_AWS_SECRET_ACCESS_KEY]
export AWS_REGION=[YOUR_AWS_REGION]
export URL=[APPLICATION_URL]
export AVATAR_URL=[AVATAR_URL]
# "You should provide a regex string without http or https"
export CORS_DOMAIN=[YOUR_CORS_DOMAIN]
# "You can use `mix phx.gen.secret` to get one"
export SECRET_KEY_BASE=[YOUR_SECRET_KEY_BASE]
export EMAIL_API_KEY=[YOUR_MAILGUN_API_KEY]
Expand Down
4 changes: 0 additions & 4 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ config :safira, SafiraWeb.Endpoint,
render_errors: [view: SafiraWeb.ErrorView, accepts: ~w(json)],
pubsub_server: Safira.PubSub

config :safira, SafiraWeb.CORS,
# Allowed domains (regex string without protocol)
domain: System.get_env("CORS_DOMAIN" || ".*")

# Configures Elixir's Logger
config :logger, :console,
format: "$time $metadata[$level] $message\n",
Expand Down
5 changes: 5 additions & 0 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ config :safira, SafiraWeb.Endpoint,
]
]

config :cors_plug,
origin: [
"http://localhost:3000"
]

# ## SSL Support
#
# In order to use HTTPS in development, a self-signed
Expand Down
10 changes: 10 additions & 0 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ config :safira, Safira.Mailer,
recv_timeout: :timer.minutes(1)
]

# :cors_plug must be configured only in compilation time
# See https://github.com/mschae/cors_plug/issues/49 for alternative solutions
# with functions
config :cors_plug,
origin: [
"https://seium.org",
"https://seium-stg.netlify.app",
"https://lazuli-stg.netlify.app"
]

# Finally import the config/prod.secret.exs
# which should be versioned separately.
# import_config "prod.secret.exs"
19 changes: 0 additions & 19 deletions lib/safira_web/cors.ex

This file was deleted.

3 changes: 1 addition & 2 deletions lib/safira_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ defmodule SafiraWeb.Endpoint do

plug Pow.Plug.Session, otp_app: :safira

# The CORS plug
plug SafiraWeb.CORS
plug CORSPlug

plug SafiraWeb.Router

Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ defmodule Safira.MixProject do
{:comeonin, "~> 5.3"},
{:bcrypt_elixir, "~> 3.0"},
{:qr_code_svg, git: "https://github.com/ondrej-tucek/qr-code-svg", tag: "v1.2.0"},
{:corsica, "~> 1.3"},
{:cors_plug, "~> 3.0"},
{:arc, "~> 0.11.0"},
# If using Amazon S3
{:ex_aws, "~> 2.4"},
Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"certifi": {:hex, :certifi, "2.9.0", "6f2a475689dd47f19fb74334859d460a2dc4e3252a3324bd2111b8f0429e7e21", [:rebar3], [], "hexpm", "266da46bdb06d6c6d35fde799bcb28d36d985d424ad7c08b5bb48f5b5cdd4641"},
"combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"},
"comeonin": {:hex, :comeonin, "5.3.3", "2c564dac95a35650e9b6acfe6d2952083d8a08e4a89b93a481acb552b325892e", [:mix], [], "hexpm", "3e38c9c2cb080828116597ca8807bb482618a315bfafd98c90bc22a821cc84df"},
"cors_plug": {:hex, :cors_plug, "3.0.3", "7c3ac52b39624bc616db2e937c282f3f623f25f8d550068b6710e58d04a0e330", [:mix], [{:plug, "~> 1.13", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "3f2d759e8c272ed3835fab2ef11b46bddab8c1ab9528167bd463b6452edf830d"},
"corsica": {:hex, :corsica, "1.3.0", "bbec02ccbeca1fdf44ee23b25a8ae32f7c6c28fc127ef8836dd8420e8f65bd9b", [:mix], [{:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "8847ec817554047e9aa6d9933539cacb10c4ee60b58e0c15c3b380c5b737b35f"},
"cowboy": {:hex, :cowboy, "2.10.0", "ff9ffeff91dae4ae270dd975642997afe2a1179d94b1887863e43f681a203e26", [:make, :rebar3], [{:cowlib, "2.12.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "3afdccb7183cc6f143cb14d3cf51fa00e53db9ec80cdcd525482f5e99bc41d6b"},
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"},
Expand Down
Loading