I need to serve some files and some headers. Specifically:
CROSS_ORIGIN_EMBEDDER_POLICY = require-corp
CROSS_ORIGIN_OPENER_POLICY = same-origin
The files I need to serve are a js file and an html file.
My current implementation look like this (but I don't know why it doesn't work):
fn open(x: PathBuf) -> String {
return fs::read_to_string(x).expect("Something went wrong");
}
#[get("/mithics")]
async fn mithics() -> impl Responder {
NamedFile::open_async("./content/mithics.html").await
}
#[get("mithics.js")]
async fn mithics_js() -> impl Responder {
let mut file = PathBuf::new();
file.push("./content/mithics.js");
HttpResponse::Ok()
.content_type(ContentType::plaintext())
.append_header(("CROSS_ORIGIN_EMBEDDER_POLICY", "require-corp"))
.append_header(("CROSS_ORIGIN_OPENER_POLICY", "same-origin"))
.body(open(file))
}
I looked online and after looking at:
- stackoverflow.com/questions/73010999/how-to-return-a-namedfile-in-a-httpresponse-using-actix-web
- The actix-web and actix-files documentation
I'm stumped