|
@@ -3,8 +3,34 @@ use std::{env, os::unix::fs::MetadataExt, path::PathBuf};
|
|
|
use std::fs::read_dir;
|
|
|
use humansize::{format_size, DECIMAL};
|
|
|
|
|
|
+use rocket::http::Header;
|
|
|
+use rocket::{Request, Response};
|
|
|
+use rocket::fairing::{Fairing, Info, Kind};
|
|
|
+
|
|
|
+pub struct Cors;
|
|
|
+
|
|
|
+#[rocket::async_trait]
|
|
|
+impl Fairing for Cors {
|
|
|
+ fn info(&self) -> Info {
|
|
|
+ Info {
|
|
|
+ name: "Cross-Origin-Resource-Sharing Middleware",
|
|
|
+ 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",
|
|
|
+ "http://127.0.0.1",
|
|
|
+ ));
|
|
|
+ response.set_header(Header::new(
|
|
|
+ "access-control-allow-methods",
|
|
|
+ "GET, PATCH, OPTIONS",
|
|
|
+ ));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
#[get("/ls/<path..>")]
|
|
|
-fn list_dir(mut path: PathBuf) -> Value {
|
|
|
+fn _list_dir(mut path: PathBuf) -> Value {
|
|
|
if path.to_string_lossy().is_empty() {
|
|
|
path = PathBuf::from(".");
|
|
|
}
|
|
@@ -80,7 +106,8 @@ fn rocket() -> _ {
|
|
|
|
|
|
rock
|
|
|
.configure(fig)
|
|
|
+ .attach(Cors)
|
|
|
.mount("/", FileServer::from("."))
|
|
|
// This is a DEBUG only feature, it gives the option to list the given directory
|
|
|
- //.mount("/", routes![list_dir])
|
|
|
+ //.mount("/", routes![_list_dir])
|
|
|
}
|