lttl1234
lttl1234

Reputation: 21

VHost config for 1 react(Frontend) and 1 laravel(Backend) not working

i am learning to create apps with react in frontend and laravel as an API in the backend.

i am working locally with wampserver, i have mod_rewrite, mod_alias and mod_negociation activated.

For some reason i can't seem to get it right!

React path is:

/${INSTALL_DIR}/www/mysite.local/frontend/build

Laravel path is:

/${INSTALL_DIR}/www/mysite.local/api/public

Here is my vhost:

<VirtualHost mysite.local:80>
    ServerName mysite.local
    DocumentRoot "${INSTALL_DIR}/www/mysite.local/frontend/build"

    # Directory settings for React frontend
    <Directory "${INSTALL_DIR}/www/mysite.local/frontend/build">
        Options +Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>

    # Serve API requests via the Laravel public folder
    Alias /api "${INSTALL_DIR}/www/mysite.local/api/public"

    <Directory "${INSTALL_DIR}/www/mysite.local/api/public">
        Options +Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog "${INSTALL_DIR}/logs/mysite.local-error.log"
    CustomLog "${INSTALL_DIR}/logs/mysite.local-access.log" common
</VirtualHost>

My api/public htaccess:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

If i remove the react folder in my vhost config, it works but when trying to make everything works together all i get is a 404 error.

The only thing i did not try is setting the api on a subdomain like api.mysite.local I also made sure that the cache is cleared and the route is registered in laravel with:

>> php artisan cache:clear
>> php artisan config:clear
>> php artisan route:clear
>> php artisan route:cache
>> php artisan route:list

result:

 GET|HEAD   / ....................................................................................................................... generated::ttXa8DVdZS9vRF40
  POST       _ignition/execute-solution ............................................ ignition.executeSolution › Spatie\LaravelIgnition › ExecuteSolutionController
  GET|HEAD   _ignition/health-check ........................................................ ignition.healthCheck › Spatie\LaravelIgnition › HealthCheckController
  POST       _ignition/update-config ..................................................... ignition.updateConfig › Spatie\LaravelIgnition › UpdateConfigController
  GET|HEAD   api/hello ............................................................................................................... generated::oWWtBen6MjSp754N
  GET|HEAD   api/test ................................................................................................................ generated::IzojuACA72Sg112k
  GET|HEAD   sanctum/csrf-cookie ............................................................... sanctum.csrf-cookie › Laravel\Sanctum › CsrfCookieController@show

                                                                                                                                                Showing [7] routes

Any input on this would be appreciated! Thanks.

Upvotes: 2

Views: 30

Answers (0)

Related Questions