<?php
// Read JSON data from the request body
$jsonData = file_get_contents('php://input');

// Escape the JSON string for safe use in a shell command
$escapedJsonData = str_replace('"', '\"', $jsonData);
// Path to your Node.js script
$nodeScript = '/var/solar/v2/source/solarapi.js';
//$nodeScript = 'D:/xampp/htdocs/solar/build/solarapi.js';

// Build the command to execute the Node.js script with the escaped JSON string as an argument
$command = "node $nodeScript";

// Execute the command with JSON data as an argument
exec("$command \"$escapedJsonData\"", $output, $returnCode);
// Check if execution was successful
if ($returnCode === 0) 
{
    // Output the result
    echo implode("\n", $output);
} 
else 
{
    // Handle error
    echo "{\"isSuccess\":false}";
}
?>
