opcodesio / log-viewer

Fast and beautiful Log Viewer for Laravel
https://log-viewer.opcodes.io
MIT License
3.39k stars 237 forks source link

fix: read mix-manifest.json #307

Closed mohammadRezaPegah closed 6 months ago

mohammadRezaPegah commented 6 months ago

check mix-manifest.json from public folder on localhost and public_html on server

arukompas commented 6 months ago

hey @mohammadRezaPegah , can you please explain why these two files were added and how does that help solve a problem? What problem were you facing anyway?

mohammadRezaPegah commented 6 months ago

Yes, of course. When you run your Laravel project on localhost and the 'public' folder is located inside the project folder, everything is fine, and there is no problem. However, when you deploy the code to the server and migrate the 'public' folder files to 'public_html', the package looks for the 'public' folder in the 'resource' folder and cannot find and read 'mix-manifest.json', resulting in a publish error: 'Log Viewer assets are not published. Please run: php artisan vendor:publish --tag=log-viewer-assets --force.'

In fact, the package assets are published successfully. However, in 'LogViewerService.php@assetsAreCurrent()' method, we use the 'public_path()' method to find and read the 'mix-manifest.json' file (by default, 'public_path()' returns '/home/..../source_code/public'). Now, in 'LogViewerService.php@assetsAreCurrent()', I first check the 'public' folder (for localhost support), and after that, I check the 'public_html' folder (for server support). If I can't find 'mix-manifest.json' in either of these paths, the application returns an assets publish error.

With this solution, the user does not need to change 'public_path()' return or any other configurations.

arukompas commented 6 months ago

@mohammadRezaPegah , you should not "migrate" anything when deploying to a production server. Your apache/nginx configuration should just serve the app from the public folder instead.

For example, if you have deployed your app to /var/www/example.com folder, which has the standard Laravel structure like app, vendor, public, etc., then you would configure your Apache like so:

    DocumentRoot /var/www/example.com/public

Or in nginx:

    root /var/www/example.com/public;

This way your production app would work just like your local app.

With this in mind, I'm going to reject this PR because it is not a solution to your problem.

Hopefully this helps! 😄

mohammadRezaPegah commented 6 months ago

Very good, I'll check this. Tank's for your time