cors_middleware.rs 660 B

12345678910111213141516
  1. use actix_cors::Cors;
  2. use actix_web::http;
  3. // https://javascript.info/fetch-crossorigin#cors-for-safe-requests
  4. // https://docs.rs/actix-cors/0.5.4/actix_cors/index.html
  5. // http://www.ruanyifeng.com/blog/2016/04/cors.html
  6. // Cors short for Cross-Origin Resource Sharing.
  7. pub fn default_cors() -> Cors {
  8. Cors::default() // allowed_origin return access-control-allow-origin: * by default
  9. // .allowed_origin("http://127.0.0.1:8080")
  10. .send_wildcard()
  11. .allowed_methods(vec!["GET", "POST", "PUT", "DELETE"])
  12. .allowed_headers(vec![http::header::ACCEPT])
  13. .allowed_header(http::header::CONTENT_TYPE)
  14. .max_age(3600)
  15. }