Comments (4)
@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.
@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.
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.
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)
- Origin validation on OPTIONS HOT 3
- No CORS headers embedded in Plug.ErrorHandler code path HOT 2
- General CORS library HOT 3
- Options Requests without `Access-Control-Request-Method` should not be halted
- Unreachable code? HOT 2
- Support Plug 1.7 dependency HOT 1
- "Access-Control-Allow-Origin" is null when using regex for origin? HOT 3
- Configuration not working with Elixir 1.9 releases HOT 3
- Regex from string HOT 1
- FunctionClauseError when origin option is a list containing a regex HOT 1
- Regex isn't working on preflight request HOT 5
- A way to enable logging - difficult to configure HOT 3
- CORS Header empty HOT 2
- Looks like init function is called during the compile time HOT 1
- Access-Control-Allow-Credentials should not be included if set to false
- Headers cannot be set dynamically
- Minor security issue with origin checks
- Using config.ex does not work HOT 1
- default config of origin: * and credentials: true seems invalid?
- cors-rfc1918
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cors_plug.