Last active
April 30, 2021 09:24
-
-
Save myckhel/7d84b0c40022bf79bc7e38596118155d to your computer and use it in GitHub Desktop.
Safely change laravel root domain from `/` to `/public` folder after deployment in production.
This file contains 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 | |
... | |
use Illuminate\Support\Facades\Http; | |
use Route; | |
use Illuminate\Http\Request; | |
class RouteServiceProvider extends ServiceProvider | |
{ | |
... | |
public function boot() | |
{ | |
$this->configureRateLimiting(); | |
$this->routes(function () { | |
Route::middleware('web') | |
->group(base_path('routes/web.php')); | |
Route::prefix('api') | |
->middleware('api') | |
->group(base_path('routes/api.php')); | |
// handle apps using old api path | |
Route::any('public/api/{any}', function (Request $request) { | |
// remove public from path | |
$paths = explode('/', $request->path()); | |
$path = implode('/', array_slice($paths, 1)); | |
// update request with new path | |
$request->server->set('REQUEST_URI', $path); | |
$request->server->set('PATH_INFO', $path); | |
// handle as a new request | |
return app()->handle($request); | |
}) | |
->middleware('api') | |
->where('any', '.*'); | |
}); | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment