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);
}
}
@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