Comments (7)
For anyone wanting/needing these features right now, you can find them working out of the box in Corsica:
https://github.com/whatyouhide/corsica
from cors_plug.
You can just construct regex differently, for instance like this:
plug CORSPlug, origin: ~r/^http:\/\/localhost:8080$|^https:\/\/some-other-domain\.com$/
from cors_plug.
I'd much prefer to pass it as a list instead of having an increasingly long long regex.
Also, what about if I want to combine regexes with simple url descriptions (as in pure strings)?
from cors_plug.
I'm just saying it's possible without having to switch packages, although I don't mind anyone going for corsica ;)
However regarding your question - it's still not that hard to do with regex and my example shows this already - you can just input any domain without any special regex treatment like this: "http://domain.com|http://example.com"
however you need to be extra careful not to accept origins like domain.com.fakedomain.com
this way - hence the $
at the end of every domain is required
from cors_plug.
And if you really prefer lists, then it's not that hard to write a function handling that yourself...
defmodule App do
def origins do
origins =
Application.get_env(:app, :origins)
|> Enum.join("$|^")
~r/^#{origins}$/
end
end
plug CORSPlug, origin: &App.origins/1
from cors_plug.
This has been discussed in the past:
#38 (comment)
My reasoning remained the same: Regex is flexible enough to do lists in one statement. There are multiple ways to create those lists programatically (including the one @kelostrada pointed out above).
I'm afraid for that reason I still don't want to implement lists of regexes.
Hope that makes sense to you!
from cors_plug.
Oh and corsica is a wonderful library, if it serves your purpose better I can highly recommend using it. No need to implement features they already have, it's great that we have two (I hope) great alternatives.
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.