Skip to content

Instantly share code, notes, and snippets.

@milesw
Created December 3, 2016 08:02
Show Gist options
  • Save milesw/832ffe73c1e9ff3af81f5148f8e0ee45 to your computer and use it in GitHub Desktop.
Save milesw/832ffe73c1e9ff3af81f5148f8e0ee45 to your computer and use it in GitHub Desktop.
Laravel Valet driver that serves static files with CORS header
<?php
class StaticCorsValetDriver extends BasicValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return bool
*/
public function serves($sitePath, $siteName, $uri)
{
return $this->isStaticFile($sitePath, $siteName, $uri);
}
/**
* Serve the static file at the given path.
*
* @param string $staticFilePath
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return void
*/
public function serveStaticFile($staticFilePath, $sitePath, $siteName, $uri)
{
header('Access-Control-Allow-Origin: *');
parent::serveStaticFile($staticFilePath, $sitePath, $siteName, $uri);
}
}
@vesper8
Copy link

vesper8 commented May 17, 2017

@milesw

I tried your solution but I can't get it to work on font files referenced inside css files

I describe my issue in detail here: laravel/valet#377

Would appreciate your feedback if you have any idea what's causing this and how to fix it?

Thanks!

@sdevore
Copy link

sdevore commented Jan 11, 2023

Thank You!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment