actix / actix-web

Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.
https://actix.rs
Apache License 2.0
21.6k stars 1.67k forks source link

Activate CORS middleware on a staticfile handler #576

Closed rjanvier closed 5 years ago

rjanvier commented 5 years ago

Since StaticFile must be registered with App::handler() it seems impossible to make it work with the full featured CORS middleware (by "full featured" I mean the one that handle the 'OPTION' preflight)

I have tried this, obviously without success

let static_file_app = App::new()
            .prefix("static_content")
            .handler("data", fs::StaticFiles::new("mydir").unwrap())
            .configure(|app| {
                Cors::for_app(app).allowed_origin(client_url.as_str()).max_age(3600).register()
 }).boxed();

Does anyone ever succeed to manage something like this? thanks.

Patryk27 commented 5 years ago

Shouldn't this belong to https://github.com/actix/actix-web?

DoumanAsh commented 5 years ago

Yes, it should, @rjanvier I'd like to transfer the issue

On the issue topic: I don't remember details right now, but the request/responses from StaticFiles should be no different from regular ones. I'd need to check it, but you can try to use logging middleware to see the outgoing and incoming requests

fafhrd91 commented 5 years ago

this should work in 1.0