PHP built-in server hosting web fonts -
i'm using php's built-in web server local development of project, so:
$ php -s localhost:8000 -t web/
inside web
directory fontawesome (an icon webfont) , web page correct includes , classes. font doesn't display correctly when served locally.
the 'network' developer tab in browser shows font correctly loading server:
200 http://localhost:8000/fonts/fontawesome-webfont.woff2?v=4.6.3
however response headers include content-type: application/octet-stream
when (i believe) should returning content-type: application/font-woff
etc.
is there way serve web fonts php's built-in web server? adding custom mime types perhaps?
from the docs:
if php file given on command line when web server started treated "router" script. script run @ start of each http request. if script returns false, requested resource returned as-is. otherwise script's output returned browser.
$ php -s localhost:8000 router.php
sample router.php adding additional mime types, not natively supported php cli webserver looks like:
<?php // router.php $path = pathinfo($_server["script_filename"]); if ($path["extension"] == "el") { header("content-type: text/x-script.elisp"); readfile($_server["script_filename"]); } else { return false; } ?>
my own router.php file including font-awesome looks this:
<?php // router.php $path = pathinfo($_server["script_filename"]); switch ($path["extension"]) { case "ttf": header("content-type: application/x-font-ttf"); break; case "woff": header("content-type: application/x-font-woff"); break; case "woff2": header("content-type: font/woff2"); break; default: return false; } readfile($_server["script_filename"]);
keep in mind won't need deploy router script, it's required local development.
Comments
Post a Comment