gianlucaz's avatar

Issue with Nova Backend & Inertia

Laravel Version: 9.21.6 Nova Version: 4.12.12 PHP Version: 8.0.21

Description: i'm currently having some Problems on my Nova Backend that occurs only on the Live Server, it works just fine on my local development machine. When i click something on the sidebar of the Backend (under "Ressources", for Example "Users") i always get a popup with an error message "All Inertia requests must receive a valid Inertia response, however a plain JSON response was received." and a dump of the JSON output. If i directly open one of the links from the sidebar (right mouse click, open in new tab) it works. Can somebody help?

Regards, Gianluca

0 likes
8 replies
ramonrietdijk's avatar

Does the problem still occur after running the following commands:

php artisan optimize:clear
php artisan nova:publish
gianlucaz's avatar

I did try clearing all caches, that didn't help. I compared the requests/responses that are generated and noticed that there some parts missing on the server. In comparison to my local machine these parts are missing: Vary: X-Inertia X-Inertia: true

speedball's avatar

Same problem here! Only happens on the live server. Any recommendations?

speedball's avatar
Level 6

ok, after some digging it seems that on my live server, which is a standard hosted server the correct headers were not sent. Nova 4 is based on Inertia which requires that the correct headers are sent otherwise the response will be interpreted as standard json. In my case (Apache + htaccess) I added:

<IfModule mod_headers.c>
    Header append X-Inertia: true
</IfModule>

to the .htaccess and it works now but I would still like to know why those headers were suppressed in the first place.

1 like
gianlucaz's avatar

@abanani That work's for us too! And yes, it would be nice to know why the headers were suppressed in the first place.

speedball's avatar

I tried to find the root of the error and in my case the headers are actually set by Laravel. When I copy (just the link) of one of the links from the menu and paste them in the browser directly everything works. Only when clicking on the links causes the error to appear.

bflow's avatar

I have the exact same problem in my local environment. I also added the following code to /public/.htaccess file but did not help <IfModule mod_headers.c> Header append X-Inertia: true </IfModule>

I still run Laravel 8 and my frontend is a Vue 2 SPA.

Any ideas where to look for the problem?

Please or to participate in this conversation.