-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1a43e7
commit d0571ff
Showing
3 changed files
with
30 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// cors.rs | ||
use rocket::{Request, Response}; | ||
use rocket::fairing::{Fairing, Info, Kind}; | ||
use rocket::http::Header; | ||
|
||
pub struct CORS; | ||
|
||
#[rocket::async_trait] | ||
impl Fairing for CORS { | ||
fn info(&self) -> Info { | ||
Info { | ||
name: "Add CORS headers to responses", | ||
kind: Kind::Response | ||
} | ||
} | ||
|
||
async fn on_response<'r>(&self, _request: &'r Request<'_>, response: &mut Response<'r>) { | ||
response.set_header(Header::new("Access-Control-Allow-Origin", "*")); | ||
response.set_header(Header::new("Access-Control-Allow-Methods", "POST, GET, PATCH, OPTIONS, PUT, DELETE")); | ||
response.set_header(Header::new("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept")); | ||
response.set_header(Header::new("Access-Control-Allow-Credentials", "true")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters