cloudflare / cloudflare/workers-rs
how to use CORS?
- Dominant language
- Rust
- Stars
- 3.7k
- Forks
- 429
- Avg merge
- 20h 28m
- Merged PRs (30d)
- 7
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Description
I'm using it this way now but I'd like confirmation that this is the way :)
```rust
#[event(fetch)]
pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> Result {
log_request(&req);
// Optionally, get more helpful error messages written to the console in the case of a panic.
utils::set_panic_hook();
// CORS
let cors = Cors::default()
.with_max_age(86400)
.with_origins(vec!["*"])
.with_methods(vec![
Method::Get,
Method::Head,
Method::Post,
Method::Options,
]);
// TRUNCATED...
let router = Router::new();
router
// TRUNCATED...
.run(req, env)
.await?
.with_cors(&cors)
```
Contributor guide
Assessment
This issue has not been assessed yet.