-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix hard-coded preflight origin #32
Comments
I still haven't decided how to do this properly. I was hoping that we could deduce the information from the controller's config somehow but that doesn't seem to be a very elegant solution given that the the Currently I think that the best solution is to add a It might be worth considering having the @0x00002a Thoughts? |
From my perspective I need to be able to have CORS access for webui backends and such. Off the top of my head, maybe it could also be done like the current routes, with an Currently I have to disable the automatic preflight stuff and handle |
I think there might have been a slight misunderstanding. I am not proposing to drop this feature. I too need it for exactly the same reason :p What I'd like to discuss is the design of how this should work - especially how the necessary information for filling the preflight response is passed into the I agree that preflights should only be generated automatically if none was provided manually. |
Yeah sorry, thats what I meant too. What I mean is, I need to have a way to specify the I also have other custom setup for the preflight such as allowed headers, and methods. Speaking of which the methods should probably be filled automagically, since we have that information. Perhaps we could expose an object that allowed customising these things, exposing the Just some ideas |
Improving the API is the entire point of this discussion/issue 😝 So, how about creating
That is already the (somewhat?) the case: malloy/lib/malloy/server/routing/router.cpp Line 170 in 8d0529b
|
🤦♀️ can't believe I missed that
I agree but I think it would be helpful to have a per-route config rather than a global or nothing situation, since certain parts of an API may have different requirements but still be mostly the same. If we allow the user to set it via regex for which routes it covers, it could reduce boilerplate/pain for the user while still being flexible enough to be global if the user wants or pinpoint precise as well. I was thinking we could actually just do this as a wrapper on Thoughts? |
Well, each (sub-)router would have its own instance of the
+1
Sounds like a good plan. struct preflight_config
{
std::string origin;
// ...
}
struct endpoint_http_preflight :
endpoint,
resource_matcher
{
preflight_config cfg;
}; and bool router::add_preflight(/* ... */); We can still have the router to optionally generate preflights automatically (if none was specified manually). |
That also works. I was thinking more like: auto add_preflight(const std::string& resource, const preflight_config& cfg) -> bool {
return add(http::method::options, resource, [cfg](const auto& req) { /* setup response based on cfg */ return res; });
} That way the user has a preflight config that can be copied and tweaked across multiple instances and isn't tied to a single endpoint. Also we could even add logic for capture group usage if we wanted to. Having it as its own endpoint might be cleaner in the long run though I guess? (though we would have to reimplement the regex matching of the regex endpoint if we wanted regex so I'm not sure) |
Today we are really good at talking about the same thing but still "disagreeing" :p |
router::router::generate_preflight_response()
currently uses a hardcoded value forAccess-Control-Allow-Origin
. This should be instead replaced by whatever configuration was passed to thecontroller
:malloy/lib/malloy/server/routing/router.cpp
Line 169 in beb0cc6
This will require that we also add a scheme field to the controller's configuration as the value for this header field needs to include the scheme if an URL is supplied.
Thinking of it, we should also allow the user of the library to specify other values such as a wildcard.
The text was updated successfully, but these errors were encountered: