34 lines
820 B
Rust
34 lines
820 B
Rust
#![feature(proc_macro_hygiene, decl_macro)]
|
|
use rocket;
|
|
use rocket_cors;
|
|
|
|
use rocket::http::Method;
|
|
use rocket::{get, routes};
|
|
use rocket_cors::{AllowedHeaders, AllowedOrigins, Error};
|
|
|
|
#[get("/")]
|
|
fn cors<'a>() -> &'a str {
|
|
"Hello CORS"
|
|
}
|
|
|
|
fn main() -> Result<(), Error> {
|
|
let allowed_origins = AllowedOrigins::some_exact(&["https://www.acme.com"]);
|
|
|
|
// You can also deserialize this
|
|
let cors = rocket_cors::CorsOptions {
|
|
allowed_origins,
|
|
allowed_methods: vec![Method::Get].into_iter().map(From::from).collect(),
|
|
allowed_headers: AllowedHeaders::some(&["Authorization", "Accept"]),
|
|
allow_credentials: true,
|
|
..Default::default()
|
|
}
|
|
.to_cors()?;
|
|
|
|
rocket::ignite()
|
|
.mount("/", routes![cors])
|
|
.attach(cors)
|
|
.launch();
|
|
|
|
Ok(())
|
|
}
|