I have a Laravel + Inertia + VueJS app. I want to use SSR (server-side rendering) for better SEO.
The commands I have used until now (with Inertia, but without SSR) have been these:
npm run dev
(to run the front-end server)php artisan serve
(to run the back-end server)
The Inertia documentation on SSR tells me I should run these commands:
npm run build
(to prepare the assets)php artisan inertia:start-ssr
(to start the server using SSR)
When I use the last two commands, here is what happens:
- When I go to port
8000
, I get a this message in my browser:Unable to connect
. - When I go to port
13714
, I get a JSON array:status "NOT_FOUND"
After reading the documentation, I’m still confused. I must be missing something. What am I doing wrong here? What commands and port should I use?
Edit:
Also, when on top of that I run my usual php artisan serve
command, my content is served on port 8000
, but as JS, not as actual HTML.
2
Answers
I was able to find an answer to my question. This has worked locally for me and should also work remotely assuming you follow the same steps I describe.
When using SSR, you need to run this command first to make sure your content is up to date:
npm run build
Then you need to open two Terminal windows and use these two commands and run two different servers:
php artisan serve
php artisan inertia:start-ssr
Then, you go to your usual port (typically
8000
), so your URL should look likehttp://localhost:8000/
.Now, if you look at the source code, you should see HTML at the very end. To see this clearly, I recommend using Chrome instead of Firefox because it has a text wrapping feature at the top of the source code, with a checkbox.
If you kill the second server (the SSR one), you won't have HTML rendering, but your app should work fine besides that.
Your meta tags should be outputted as HTML as well when using SSR.
Im also having the same issue with Inertia. Our web platform is up and running smooth but had to configure it for SSR since we are not totally visible to web crawlers.Our problem is with React components that doesn’t do well with SSR. Does someone here have the same issue?, how did you solve it?, any work-arounds with ssr not initiating after running