From f17fba44fd81dd40ebf37a5cfc37fb8763025ea0 Mon Sep 17 00:00:00 2001 From: Sergey Zubkov Date: Thu, 16 Nov 2023 17:52:19 +0300 Subject: [PATCH] setup CORS --- lib/market_web/endpoint.ex | 12 ++---------- mix.exs | 3 ++- mix.lock | 1 + 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/market_web/endpoint.ex b/lib/market_web/endpoint.ex index 5b86a0a..6fa7b0a 100644 --- a/lib/market_web/endpoint.ex +++ b/lib/market_web/endpoint.ex @@ -1,6 +1,8 @@ defmodule MarketWeb.Endpoint do use Phoenix.Endpoint, otp_app: :market + plug CORSPlug, origin: [System.get_env("FRONT", "localhost:3000")] + # The session will be stored in the cookie and signed, # this means its contents can be read but not tampered with. # Set :encryption_salt if you would also like to encrypt it. @@ -11,16 +13,6 @@ defmodule MarketWeb.Endpoint do same_site: "Lax" ] - # Serve at "/" the static files from "priv/static" directory. - # - # You should set gzip to true if you are running phx.digest - # when deploying your static files in production. - plug Plug.Static, - at: "/", - from: :market, - gzip: false, - only: MarketWeb.static_paths() - # Code reloading can be explicitly enabled under the # :code_reloader configuration of your endpoint. if code_reloading? do diff --git a/mix.exs b/mix.exs index 7d6b229..adfc1f9 100644 --- a/mix.exs +++ b/mix.exs @@ -45,7 +45,8 @@ defmodule Market.MixProject do {:jason, "~> 1.2"}, {:plug_cowboy, "~> 2.5"}, {:ex_machina, "~> 2.7.0"}, - {:faker, "~> 0.17", only: :test} + {:faker, "~> 0.17", only: :test}, + {:cors_plug, "~> 3.0"} ] end diff --git a/mix.lock b/mix.lock index 3fd5828..81dd6b2 100644 --- a/mix.lock +++ b/mix.lock @@ -2,6 +2,7 @@ "bcrypt_elixir": {:hex, :bcrypt_elixir, "3.0.1", "9be815469e6bfefec40fa74658ecbbe6897acfb57614df1416eeccd4903f602c", [:make, :mix], [{:comeonin, "~> 5.3", [hex: :comeonin, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "486bb95efb645d1efc6794c1ddd776a186a9a713abf06f45708a6ce324fb96cf"}, "castore": {:hex, :castore, "1.0.3", "7130ba6d24c8424014194676d608cb989f62ef8039efd50ff4b3f33286d06db8", [:mix], [], "hexpm", "680ab01ef5d15b161ed6a95449fac5c6b8f60055677a8e79acf01b27baa4390b"}, "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"}, "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"}, "cowlib": {:hex, :cowlib, "2.12.1", "a9fa9a625f1d2025fe6b462cb865881329b5caff8f1854d1cbc9f9533f00e1e1", [:make, :rebar3], [], "hexpm", "163b73f6367a7341b33c794c4e88e7dbfe6498ac42dcd69ef44c5bc5507c8db0"},