imazen / imageflow-dotnet-server

A super-fast image server to speed up your site - deploy as a microservice, serverless, or embeddable.
https://docs.imageflow.io
GNU Affero General Public License v3.0
246 stars 33 forks source link

add cors headers to file response #46

Closed keyone2693 closed 3 years ago

keyone2693 commented 3 years ago

tnx for the awesome package

I have something like this

app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider( Path.Combine(env.ContentRootPath, "files")), RequestPath = "/files", OnPrepareResponse = ctx => { ctx.Context.Response.Headers.Append("Access-Control-Allow-Origin", "*"); ctx.Context.Response.Headers.Append("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); } });

and it's working just fine it's for when I want to fetch an image from my client with js

but when I am using image flow its stop working and when I looked at the network tab I can see that those headers were not added

and I have this error

Access to fetch at 'https://....8.png?width=150' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

how can I solve this?

lilith commented 3 years ago

Would you be willing to share your solution in case others run across this issue?

On Wed, Feb 10, 2021, 9:01 AM Keyvan Abodollahzadeh < notifications@github.com> wrote:

Closed #46 https://github.com/imazen/imageflow-dotnet-server/issues/46.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/imazen/imageflow-dotnet-server/issues/46#event-4315588806, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2LH6HRHXBMGBXIYX6RXTS6KUVBANCNFSM4XMZKZWQ .

keyone2693 commented 3 years ago

Actually, Just change my client to work without fetching images

I think the asp core own cors policy is enough And maybe we don't need to add cors policy headers to the static file itself

But for sure when we using image flow Those headers that added with UseStaticFiles just disappear

lilith commented 3 years ago

The middleware isn't involved with the static file middleware - nothing from there would be intended to affect images.

On Wed, Feb 10, 2021, 4:02 PM Keyvan Abodollahzadeh < notifications@github.com> wrote:

Actually, Just change my client to work without fetching images

I think the asp core own cors policy is enough And maybe we don't need to add cors policy headers to the static file itself

But for sure when we using image flow Those headers that added with UseStaticFiles just disappear

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/imazen/imageflow-dotnet-server/issues/46#issuecomment-777094378, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2LH2XDFBAQ6HIVBFMCLDS6MF73ANCNFSM4XMZKZWQ .

keyone2693 commented 3 years ago

I was talking about affecting static files response headers