Last active
November 8, 2022 10:18
-
-
Save Mtillmann/ea4d3c0e24f30d1bc9504f1151d2d941 to your computer and use it in GitHub Desktop.
Custom HMR URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
use Illuminate\Http\Request; | |
class CustomHMRHotFile | |
{ | |
/** | |
* Allow for different HMR URLs, regardless of what vite-plugin generates. | |
* | |
* @see https://medium.com/@mtillmann_68557/using-laravel-9-breeze-with-ddev-and-vite-3e40abd2954a | |
* @see https://github.com/laravel/vite-plugin/issues/156 | |
* | |
* Install: | |
* - copy this file to app/Http/Middleware/CustomHMRHotFile.php | |
* - add `\App\Http\Middleware\CustomHMRHotFile::class` to app/Http/Kernel.php: Kernel::$middleware[] | |
* | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next | |
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse | |
*/ | |
public function handle(Request $request, Closure $next) | |
{ | |
if (is_file(public_path('hot'))) { | |
$originalContent = file_get_contents(public_path('hot')); | |
$customContent = str_replace('http://', 'https://', $originalContent); | |
if ($originalContent !== $customContent) { | |
file_put_contents(public_path('hot'), $customContent); | |
} | |
} | |
return $next($request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment