Adds vuejs with vue-cli, adds cors fairing to rocket

This commit is contained in:
2019-02-05 21:34:54 +01:00
parent bcc0564f2a
commit f220c6c960
16 changed files with 313 additions and 12 deletions

View File

@@ -3,11 +3,15 @@
#[macro_use] extern crate rocket;
#[macro_use] extern crate rocket_contrib;
#[macro_use] extern crate serde_derive;
extern crate rocket_cors;
extern crate cookbook;
use std::path::Path;
use rocket::response::{NamedFile, status::NotFound};
use rocket::{
response::{NamedFile, status::NotFound},
http::Method,
};
use rocket_cors::{AllowedHeaders, AllowedOrigins, Error};
#[get("/")]
fn index() -> Result<NamedFile, NotFound<String>> {
@@ -66,9 +70,25 @@ mod api {
}
}
fn main() {
fn main() -> Result<(), Error> {
let (allowed_origins, failed_origins) = AllowedOrigins::some(&["http://localhost:8080"]);
assert!(failed_origins.is_empty());
// You can also deserialize this
let cors = rocket_cors::CorsOptions {
allowed_origins: 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()
.attach(api::CookbookDbConn::fairing())
.mount("/", routes![index])
.mount("/api", routes![api::recipes_list, api::delete_recipe]).launch();
.mount("/api", routes![api::recipes_list, api::delete_recipe])
.attach(cors)
.launch();
Ok(())
}