diff options
| author | Fuwn <[email protected]> | 2021-04-28 12:56:52 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-04-28 12:56:52 +0000 |
| commit | 2196bd82ce7f23cd8c9b83482f616ddb72dbfcc8 (patch) | |
| tree | 8157302332f54069ff11b7470d52342c5a8befa5 | |
| parent | Merge branch 'main' of https://github.com/senpy-club/api into main (diff) | |
| download | api-worker-2196bd82ce7f23cd8c9b83482f616ddb72dbfcc8.tar.xz api-worker-2196bd82ce7f23cd8c9b83482f616ddb72dbfcc8.zip | |
fix?: CORS
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | src/main.rs | 32 |
2 files changed, 24 insertions, 9 deletions
@@ -20,3 +20,4 @@ serde = "1.0.125" serde_derive = "1.0.125" rand = "0.8.3" dotenv = "0.15.0" +rocket_cors = "0.5.2" diff --git a/src/main.rs b/src/main.rs index 50e4d9b..66f914c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,17 +11,31 @@ pub mod routes; pub mod structures; pub mod utils; +use rocket_cors as cors; + #[launch] fn rocket() -> _ { dotenv::dotenv().ok(); - rocket::build().mount("/", routes![routes::index]).mount( - "/api/v1", - routes![ - routes::github, - routes::languages, - routes::language, - routes::random - ], - ) + rocket::build() + .manage( + cors::CorsOptions { + allowed_origins: cors::AllowedOrigins::all(), + allowed_methods: cors::AllowedMethods::new(), + allowed_headers: cors::AllowedHeaders::all(), + ..Default::default() + } + .to_cors() + .unwrap(), + ) + .mount("/", routes![routes::index]) + .mount( + "/api/v1", + routes![ + routes::github, + routes::languages, + routes::language, + routes::random + ], + ) } |