Hi everyone, I need some help with a weird issue I’m facing.
I’m building a system where I have a React app running alongside a PHP backend. The PHP backend has multiple API endpoints that work perfectly fine, except for one specific service that uses ssh2_connect.
Here’s my problematic PHP code:
case 'remote_connection':
$server_port = 22;
$message = 'connection_test';
$ssh_session = ssh2_connect($remote_host, $server_port);
if(!$ssh_session) die("Failed to establish connection");
Whenever this code runs, instead of getting my expected response, I get the React app’s main HTML page returned. All my other API calls work fine, but this ssh2_connect one behaves differently.
My setup is pretty standard. I have a React app created with create-react-app running on port 3000. The backend PHP files are in the same project structure. I’m using React Router v6 for handling frontend routes.
The weird part is that when I comment out the ssh2_connect line, everything works as expected. But as soon as I include that function call, React Router seems to take over and serves the index.html instead of my API response.
I can access other endpoints like http://localhost:3000/api/users
without any issues, but http://localhost:3000/api/remote_connection
returns HTML instead of JSON.
I suspect this might be related to how React Router handles unknown routes, but I can’t figure out why only the ssh2_connect function triggers this behavior. When I run the PHP file directly from command line, it works perfectly.
Has anyone encountered something similar? Any ideas on what might be causing this conflict between ssh2_connect and React Router?