Anybody to help me ? ;)
Route not found only in production
Hello,
I work on an existing Laravel application (v7.24) and a web route was defined like this.
$proxy_url = getenv('PROXY_URL');
$proxy_scheme = getenv('PROXY_SCHEME');
if(env('APP_ENV') != 'local') {
if (!empty($proxy_url)) {
URL::forceRootUrl($proxy_url);
}
if (!empty($proxy_scheme)) {
URL::forceScheme($proxy_scheme);
}
}
Route::get('/', function () {
return view('welcome');
});
Route::get('store', function ()
{
if (!request()->input('file')) {
abort(404);
}
$filename = request()->input('file');
$path = 'public/' . $filename;
if (!Storage::exists($path)) {
abort(404);
}
return Storage::response($path);
});
Here is an example of how the route is used from the frontend developed with nuxt / VueJS.
http://mysuperdomain.com/store?file=%2Fbup%2F9XrKJaJaKvDMo3k0mPPD6MvSNj3i89n801K8s9PT.jpg"
The other routes are API routes.
In development and in production, php artisan route:list shows that the route exists.
The route displays the image in development mode, but the route is not found in production mode (404 error). I have tested to change the abort(404) in the closure (for example with 405 error) and I also have a 404 error, in other words the route is not recognized in production mode.
I know that there are bad pratices in this code, I don't have written it myself, but is there any reason for which the route could be not recognized only in production mode ?
I specify that the routes are not cached in production on the demo server and the CORS problems seem to be solved.
I think that the problem is necessarily binded to the server configuration or perhaps any environment variable or something with the frontend or ... but I have no idea where I could search, at what part of the code I could look to find a solution.
If you have any idea, it would be great.
Thanks a lot.
Vincent
Problem solved => the dev who has installed Laravel on the webserver has set a bad configuration.
APP_URL=https://domain.com/public
And the Apache server pointed to the root folder of the project instead of pointing to the public folder of the server.
From the beginning I thought about that, but I didn't have access to the demo server, so I have had to ask to have the right informations.
Please or to participate in this conversation.