Code Monkey home page Code Monkey logo

Comments (4)

mschae avatar mschae commented on July 20, 2024

@artburkart Sorry for replying so late.

As far as I know apart from using the (default) wildcard * (that will simply allow all origins) you can set a space delimited list of origins like so:

plug CORSPlug, origin: "example.com example.org foo.com"

Hope that makes sense.

from cors_plug.

mschae avatar mschae commented on July 20, 2024

@artburkart Apologies, looks like the list standard isn't well supported. I wasn't aware... @jer-k added a PR and I just released v1.1.0 that allows to set a list of origins in the origin: config key.

Hope that helps!

from cors_plug.

jer-k avatar jer-k commented on July 20, 2024

I just thought I would add one last thing there.

pry(1)> conn
%Plug.Conn{adapter: {Plug.Adapters.Cowboy.Conn, :...}, assigns: %{},
 before_send: [#Function<1.63666232/1 in Plug.Logger.call/2>,
  #Function<0.63970881/1 in Phoenix.LiveReloader.before_send_inject_reloader/1>],
 body_params: %{}, cookies: %Plug.Conn.Unfetched{aspect: :cookies},
 halted: false, host: "localhost", method: "GET", owner: #PID<0.594.0>,
 params: %{}, path_info: ["books"], peer: {{127, 0, 0, 1}, 54513}, port: 4000,
 private: %{PhoenixGluestickApi.Router => {[], %{GraphQL.Plug.Endpoint => []}},
   :phoenix_action => :index,
   :phoenix_controller => PhoenixGluestickApi.BookController,
   :phoenix_endpoint => PhoenixGluestickApi.Endpoint, :phoenix_format => "json",
   :phoenix_layout => {PhoenixGluestickApi.LayoutView, :app},
   :phoenix_pipelines => [:api],
   :phoenix_route => #Function<7.83685994/1 in PhoenixGluestickApi.Router.match_route/4>,
   :phoenix_router => PhoenixGluestickApi.Router,
   :phoenix_view => PhoenixGluestickApi.BookView,
   :plug_session_fetch => #Function<1.91252167/1 in Plug.Session.fetch_session/1>},
 query_params: %{}, query_string: "", remote_ip: {127, 0, 0, 1},
 req_cookies: %Plug.Conn.Unfetched{aspect: :cookies},
 req_headers: [{"accept", "application/json, text/plain, */*"},
  {"user-agent", "axios/0.9.1"}, {"host", "localhost:4000"},
  {"connection", "close"}], request_path: "/books", resp_body: nil,
 resp_cookies: %{},
 resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"},
  {"x-request-id", "o62r797gj82usvpdkc7pt66hgutf9635"},
  {"access-control-allow-origin", nil}, {"access-control-expose-headers", ""},
  {"access-control-allow-credentials", "true"}], scheme: :http, script_name: [],
 secret_key_base: "/VuSjVh9ADlr+UPsWvmCTLixXdp3FUsavpVD+Jy6pYrOqVrBQePClJ6frP5d0G4K",
 state: :unset, status: nil}
pry(2)> respawn

Interactive Elixir (1.2.0) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> [info] Sent 200 in 7200ms
iex(1)> [error] Bad value on output port 'tcp_inet'

The error appears because of the nil in {"access-control-allow-origin", nil} from what I can tell. Everything about it seems to reference Erlang. Passing [] back is probably a better solution because the error actually causes the server to respond

from cors_plug.

mschae avatar mschae commented on July 20, 2024

Hm good catch I never actually tested that case...

I'll just not return the header when that happens...

from cors_plug.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.