-
Notifications
You must be signed in to change notification settings - Fork 39
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
Configure CORS headers globally #46
Comments
I've been researching about this topic. Ideally, we should implement it using an Actix middleware. However, I will delay this implementation because this is already configurable by the workers. |
Hi @Angelmmiguel. I can work on this issue, can you please assign it to me? |
That's amazing @Narayanbhat166. I assigned the issue to you 😄. Feel free to ask any question or suggest different approaches to complete this issue. |
Hi @Angelmmiguel #[worker]
fn reply(req: Request<String>) -> Result<Response<Content>> {
Ok(http::Response::builder()
.status(200)
.header("Access-Control-Allow-Origin", "*")
.header("x-generated-by", "wasm-workers-server")
.body(String::from("Hello wasm!").into())?)
}
What value would this key have, is it like a boolean flag, which would set minimum permissive headers required to enable cors? |
Hello @Narayanbhat166! You are totally right about adding CORS headers to the workers. This is posible in all languages and it's the current way to do it. However, there are certain apps that exposes all the endpoints and including the CORS headers in all workers could be tedious. To simplify it, the |
Cross-Origin Resource Sharing (CORS) is a series of security policies to avoid a web browser fetching resources from a different domain. By default, CORS will block any request that a website makes to a different domain.
However, servers can set the CORS HTTP headers to indicate the browser they are fine to process the request. CORS can be configured using several headers. Some of them provides a global policy while others helps to add granularity to the requests:
Access-Control-Allow-Origin: http://example.com
Access-Control-Allow-Methods: POST, GET, OPTIONS
Access-Control-Allow-Headers: Content-Type
Access-Control-Max-Age: 10000
I recommend you to check the Cross-Origin Resource Sharing (CORS) documentation about the different headers and behaviors.
On
wws
, we plan to provide two different approaches to set theCORS
policy:--cors
option. This option will configure theAccess-Control-Allow-Origin
header. It will be applied to all requests--cors
option. If both are set, the worker value will be sentThe text was updated successfully, but these errors were encountered: