Comments (3)
In the end, I'm not exactly certain where my configurations were wrong because I tried so many variations. But for anybody else facing this problem, the code has zero logging. What I ended up doing was editing deps/cors_plug/lib/cors_plug.ex, and putting |> IO.inspect into places around init and pulling up the configs, then running queries until I was able to find exactly how things matched. Difficult, but workable.
from cors_plug.
I’ll glad you figured it out knowing full well how frustrating these things can be.
I would’ve recommended what you ended up doing anyway which is editing the source lib. I don’t think there’s a good way to add generic logging as in most cases it’d just be noise.
Thanks for sharing your journey tho, I’ll keep it in mind if there’s ever a discussion around or need for logging.
from cors_plug.
@mschae I would suggest adding something to the docs around how to debug this. I know I've worked with others who've been equally frustrated. Even just instructions on how to do inline debugging. I.e. go to line ... and add |> IO.inspect, etc, if you are not seeing it match the output you are expecting.
What is most important:
- It only pays attention to the origin header -- which is client submitted and has no relation to conn.remote_ip. To see this add a debug |> IO.inspect to
request_origin
around line 159. - Visually identify how that compares to what is actually coming into the configs, by adding something around the stages of init to verify your configurations are merging in correctly.
But honestly you could add debug/log function easily enough as a configuration option that logs these same things, then just add a default that disables it, where the config can add it in.
For whatever reason, I have noticed that the libs in Elixir are frighteningly low on debugging/logging capabilities. I suspect it's, in part, the nature of people wanting to optimize the pattern matching pipelines, without adding extra heuristics. But the side effect of this is a high barrier to entry for new developers, many I even know who just give up and go back to something a little more user-friendly.
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
- 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.