I am trying to run JS code in the backend using PHP but with no success so far.
Problem:
I restricted access to the API of our MVP to the localhost only, and I would like to call the API via Javascript via the backend (since the request would be blocked if called by the frontend). I thought of calling the Javascript script via PHP with the following code:
<?php
echo '<script type="text/JavaScript">
fetch("https://api.example.com:endpoint");
</script>'
;
?>
and added a print in the API to check if the router is being called.
Issue
When loading the page I get no error in console, nor I get a print, so I expect that JS is running on fronend and not backend. Is there a way to make JS code run in backend?