philiplb / CRUDlex

CRUDlex is an easy to use CRUD generator for Symfony 4 and Silex 2 which is great for auto generated admin pages
https://philiplb.de/crudlex/
MIT License
109 stars 23 forks source link

Failed MimeType for stylesheets and JS since 0.12.0 ver. #95

Closed stingmu closed 6 years ago

stingmu commented 7 years ago

Since CRUDlex version 0.12.0 all static files (css,js,...) - get mimetype "text/plain" and GoogleChrome/Firefox show warnings in console. Apache mimetypes - is ok, PHP fileinfo extension - installed. Screenshot ver. 0.12.0 Screenshot ver. 0.11.0 How can I resolve this bug to use CRUDlex with valid CSS and JS? Thank you very much! P.S. Sorry for my english)

bauer01 commented 7 years ago

same problem here

philiplb commented 7 years ago

I see, thank you. Will have a look.

philiplb commented 6 years ago

Hm, I'm having a hard time to reproduce this, I get the correct content type.

➜ ~ curl -I 'http://localhost/CRUDlexSample/web/crud/resource/static?file=css/vendor/select2/select2.min.css' HTTP/1.1 200 OK Date: Fri, 24 Nov 2017 09:27:21 GMT Server: Apache/2.4.25 (Unix) PHP/7.1.0 Last-Modified: Tue, 13 Sep 2016 21:06:39 GMT ETag: "3b5c-53c69fd1815c0" Accept-Ranges: bytes Content-Length: 15196 Content-Type: text/css

screen shot 2017-11-24 at 10 32 49

Do you have any URL or minimum example where this happens?

are3 commented 6 years ago

Hello, First, philiplbb thanks for you work, that's awesome!

Same problem here

curl -I 'https://localhost/bo/crud/resource/static?file=css/vendor/select2/select2.min.css' HTTP/1.0 200 OK Date: Mon, 27 Nov 2017 06:16:08 GMT Server: Apache/2.4.10 (Debian) Content-Disposition: attachment; filename="select2.min.css" Content-Length: 15196 Cache-Control: public ETag: "1503435368" Vary: Accept-Encoding Connection: close Content-Type: text/plain;charset=UTF-8

Give in navigator an unstyled result without javascript too.

product:13 Resource interpreted as Stylesheet but transferred with MIME type text/plain: "https://localhost/bo/crud/resource/static?file=css/vendor/select2/select2-bootstrap.min.css".

Think "$filesystem->getMimetype(basename($file))" l604 of ControllerProvider get bad result. But don't know why.

For example, with the file vendor/philiplb/crudlex/src/CRUDlex/../static/css/vendor/bootstrap/bootstrap.min.css :

  1. $filesystem->getMimetype(basename($file)) return text/plain
  2. mime_content_type($file) return text/plain
  3. file --mime-type return too text/plain I have the same comportement with other CSS (outside crudlex)

No definitive solution for the moment because the problem is so strange. But If i replace mimeType at line 612 of ControllerProvider by text/css, that work fine.

philiplb commented 6 years ago

Thanks for the detailed description and debugging. :) Flysystem uses finfo_file for detecting the mimetype. http://php.net/manual/de/function.finfo-file.php . Accordingly to http://php.net/manual/de/function.finfo-file.php , this requires PECL fileinfo >= 0.1.0. Is that available on your system? Else, I'm thinking about falling back to the old mechanism of guessing the mimetype in this endpoint by extension. This should be sure as it is static. Maybe generating a hard coded mapping would do it as well.

RaphArbuz commented 6 years ago

I have file info 1.0.5 on my Mac and face the same issue. Any other idea? Thanks.

philiplb commented 6 years ago

(Finally) fixed via https://github.com/philiplb/CRUDlex/commit/ffd60cee12b7a85999b42a44a54a13bcc8e97a7b Just comment if this doesn't fix it for you. 0.13.0 will be released shortly having this fix.

philiplb commented 6 years ago

0.13.0 is released, containing the fix.