Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hrsa's avatar
Level 5

API returns text/html code 200 instead of JSON with error

Dear artisans, I'm looking for your experience with Inertia, for a JSON issue I can't fix properly. Here is the problematic page on GitHub (https://github.com/hrsa/calendize/blob/master/resources/js/Pages/Auth/Login.vue).

I do an API call to the controller (https://github.com/hrsa/calendize/blob/master/app/Http/Controllers/UserController.php) to check if user's email exists and it works well - until, in a day or so, it doesn't. Nothing changes in the code, but the response starts coming back as text/html, thus messing up the logic. What's really frustrating is that this behavior is random - the app may run 1,2,3 days - and suddenly goes into "text/html" mode when calling the API. What's more, i've dumped the controller response - and it's JSON, as one expects. So it gets transformed somewhere... but where? The code seems logical and fine, what 🐘 in the room am I missing here?

0 likes
7 replies
hrsa's avatar
Level 5

@gych Thanks for the idea! I actually didn't know about that package, it's definitely worth using.

However, i feel that the problem is elsewhere, because the same "200 text/html instead of what was requested" seems more general with Inertia. I also have the same problem with the login controller, which is supposed to return a 302 redirect (and it does normally), but sometimes it also returns "200 text/html" for no apparent reason. For example, i've rebooted the server and now it works perfectly, but in a day or so it will switch to "200 text/html" again.

1 like
hrsa's avatar
Level 5

Narrowed it down to a potential nginx problem, since the FIRST response is actually returned as "200 text/html". If a request is repeated - the response has correct code. If you have ever had such issues with nginx, i'd be really thankful for your insights!

1 like
hrsa's avatar
Level 5

Finally, the culprit was gzip compression in my nginx config. After having disabled gzip, i get consistent responses with correct codes!

gych's avatar

@hrsa Good that you found the cause of the issue. Please don't forget to mark your thread as solved.

hrsa's avatar
hrsa
OP
Best Answer
Level 5

I think i got it right this time! Let me share the process with those who'll read this thread - and maybe it'll help someone sometime. The culprit wasn't nginx, because the issue came back. I asked for help everywhere i could (with no reaction whatsoever), and started examining the system again. The server went into text/html mode randomly - sometimes in an hour after deployment, sometimes - in a day or two. But it was never longer than 2 days. When getting those pesky text/html responses, i noticed the increased response time - it grew from 200-300 ms to 950-1500 ms. That got me thinking - if nothing else is happening on the server, why does it become so slow all of a sudden? So i ssh'd to the server, and started looking at the load. Memory usage seemed OK, but i noticed that the CPU was loaded at 93%! After 10 minutes, CPU load didn't decrease at all, so i started looking for a reason why the usage was so high - using top to find out that the php container was using all that power and then - using docker top php to see that there were some strange processes /tmp/kinsing and /tmp/kdevtmpfsi running for a long time and using CPU.

Then, with some googling, it wasn't hard to figure out that it was a crypto-miner malware the crept it through the port 9000 which was exposed by mistake. Fortunately, it ONLY invaded the docker container - so a quick rebuild was enough to get rid of it instantly. After properly sanitizing the exposed ports - i saw a multitude of incoming connections trying to start a "debugging" session on my previously exposed 9000 port - so yeah, that finally was the logical answer to this random bug!

The moral of the story is simple - be sure to never expose more ports than needed in your docker configuration and your server! I hope this helps someone who struggles too!

1 like
lambae96's avatar

@hrsa thanks you very very very very very very very very very very very very very very very very very very much sir, i looking for this issue 2 weeks and almost give up. i dont use laracast but i need to thank you then i create account and cmt this <3 Thanks alot, keep going this for our comunity is bigger

1 like

Please or to participate in this conversation.