mirror of
https://github.com/TeamPiped/sponsorblock-mirror.git
synced 2024-12-12 21:30:36 +05:30
Add cors for official instance.
This commit is contained in:
parent
e00d754521
commit
cccc095de8
@ -1,5 +1,6 @@
|
|||||||
[release]
|
[release]
|
||||||
address = "0.0.0.0"
|
address = "0.0.0.0"
|
||||||
|
log_level = "off"
|
||||||
|
|
||||||
[debug.databases]
|
[debug.databases]
|
||||||
sponsorblock = { url = "postgresql://sponsorblock:password123@localhost" }
|
sponsorblock = { url = "postgresql://sponsorblock:password123@localhost" }
|
||||||
|
31
src/main.rs
31
src/main.rs
@ -6,8 +6,9 @@ use std::thread::sleep;
|
|||||||
use std::time::{Duration, Instant, SystemTime};
|
use std::time::{Duration, Instant, SystemTime};
|
||||||
|
|
||||||
use diesel::connection::SimpleConnection;
|
use diesel::connection::SimpleConnection;
|
||||||
use rocket::{Build, Rocket};
|
use rocket::{Build, Request, Response, Rocket};
|
||||||
use rocket::fairing::AdHoc;
|
use rocket::fairing::{AdHoc, Fairing, Info, Kind};
|
||||||
|
use rocket::http::Header;
|
||||||
use rocket_sync_db_pools::database;
|
use rocket_sync_db_pools::database;
|
||||||
use tokio::time::interval;
|
use tokio::time::interval;
|
||||||
|
|
||||||
@ -38,6 +39,29 @@ async fn run_migrations(rocket: Rocket<Build>) -> Rocket<Build> {
|
|||||||
rocket
|
rocket
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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"));
|
||||||
|
response.set_header(Header::new("Access-Control-Allow-Headers", "*"));
|
||||||
|
response.set_header(Header::new("Access-Control-Allow-Credentials", "true"));
|
||||||
|
if request.method() == rocket::http::Method::Options {
|
||||||
|
response.set_streamed_body(tokio::io::empty());
|
||||||
|
response.set_status(rocket::http::Status::Ok);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static mut LAST_UPDATE: Option<SystemTime> = None;
|
static mut LAST_UPDATE: Option<SystemTime> = None;
|
||||||
|
|
||||||
#[launch]
|
#[launch]
|
||||||
@ -95,5 +119,6 @@ fn rocket() -> Rocket<Build> {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
).mount("/", routes![skip_segments])
|
).attach(CORS)
|
||||||
|
.mount("/", routes![skip_segments])
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user