routes: use rocket_cors crate to handle CORS

Signed-off-by: ATechnoHazard <amolele@gmail.com>
This commit is contained in:
Amogh Lele 2020-08-05 23:07:59 +05:30
parent 3d90c6f9bf
commit 51591530d0
No known key found for this signature in database
GPG Key ID: F475143EDEDEBA3C
5 changed files with 50 additions and 11 deletions

38
Cargo.lock generated
View File

@ -669,7 +669,7 @@ dependencies = [
"time",
"traitobject",
"typeable",
"unicase",
"unicase 1.4.2",
"url 1.7.2",
]
@ -808,6 +808,7 @@ dependencies = [
"jsonwebtoken",
"rocket",
"rocket_contrib",
"rocket_cors",
"serde",
"serde_derive",
"serde_json",
@ -1386,6 +1387,22 @@ dependencies = [
"serde_json",
]
[[package]]
name = "rocket_cors"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea20696dc46308d0ca06222905fe38e02b8e46c087af9c82ea85cdc386271076"
dependencies = [
"log 0.4.8",
"regex 1.3.9",
"rocket",
"serde",
"serde_derive",
"unicase 2.6.0",
"unicase_serde",
"url 2.1.1",
]
[[package]]
name = "rocket_http"
version = "0.4.5"
@ -1741,6 +1758,25 @@ dependencies = [
"version_check 0.1.5",
]
[[package]]
name = "unicase"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
dependencies = [
"version_check 0.9.2",
]
[[package]]
name = "unicase_serde"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ef53697679d874d69f3160af80bc28de12730a985d57bdf2b47456ccb8b11f1"
dependencies = [
"serde",
"unicase 2.6.0",
]
[[package]]
name = "unicode-bidi"
version = "0.3.4"

View File

@ -29,6 +29,7 @@ bcrypt = "0.8.1"
chrono = "0.4.13"
uuid = { version = "0.8.1", features = ["serde", "v4"] }
jirachi = { version = "0.1.4", features = ["collision-resistant"] }
rocket_cors = "0.5.1"
[dev-dependencies]
diesel_cli = { version = "1.4.1", default-features = false, features = ["postgres"] }

View File

@ -1,5 +1,5 @@
use crate::api::fairings::cors::CORS;
use rocket::Rocket;
use rocket_cors::CorsOptions;
pub mod health;
pub mod paste;
@ -8,8 +8,9 @@ pub mod user;
pub fn fuel(rocket: Rocket) -> Rocket {
let mut rocket = rocket;
let cors = CorsOptions::default().to_cors().unwrap();
rocket = health::fuel(rocket);
rocket = paste::fuel(rocket);
rocket = user::fuel(rocket);
rocket.attach(CORS())
rocket.attach(cors)
}

View File

@ -1,28 +1,28 @@
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use]
extern crate rocket;
extern crate rocket_contrib;
#[macro_use]
extern crate diesel;
#[macro_use]
extern crate diesel_migrations;
#[macro_use]
extern crate rocket;
extern crate rocket_contrib;
#[macro_use]
extern crate serde;
#[macro_use]
extern crate serde_json;
#[macro_use]
extern crate slog;
use slog::{Drain, Logger};
use slog_async;
use slog_term;
pub mod api;
pub mod core;
pub mod schema;
pub mod utils;
use slog::{Drain, Logger};
use slog_async;
use slog_term;
embed_migrations!("migrations");
fn run_migrations(logger: &Logger) {

View File

@ -1,4 +1,5 @@
use jirachi::Jirachi;
use jirachi::collision_resistant::Jirachi;
use jirachi::Wishable;