Currently I am working on a React folder with some PHP in public folder.
Structure
.
├── pubic
│ ├── api
│ └── co.php
├── _src
│ ├── api
│ └── components
│ └── index.tsx
├── package.json
└── node_modules
The public folder contains PHP files that changes Requests/Responses to client/API server(made by diff company).
I added another endpoint/PHP file in public folder but cannot seem to access it when testing on localhost. My coworker has mentioned that I need to update changes in staging server to test out changes in PHP folder.
Is there a better way to test locally so I do not have to update server everytime I make changes in public folder adding PHP files?
/src/api/co/reg/index.ts
import { TRequestConfig, TRequestParams } from '../..';
export { CoRes } from './CoRes.class';
export const coRequestConfig: TRequestConfig = {
endpoint: '/tempo/api/co.php',
method: 'POST',
useMock: false,
mockFunc: params => {
return {
ok: true,
body: '{}',
};
},
params2request: (params): TRequestParams => {
return {
body: params ? params.body : {},
};
},
};
/public/api/co.php
<?php
$ch = curl_init();
$isDev = $_SERVER['SERVER_NAME'] === 'stg.cooo.ca' || $_SERVER['SERVER_NAME'] === 'lol.ca';
$protocol = $isDev ? 'https://cooo.com' : 'https://cooo.prod.com';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$url = "${protocol}/aa/api/co/used";
$data = file_get_contents('php://input');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
} else {
$couponId = $_GET['couponId'];
$url = "${protocol}/aa/api/co/${couponId}";
curl_setopt($ch, CURLOPT_URL, $url);
}
if ($isDev) {
curl_setopt($ch, CURLOPT_USERPWD, "1234:1122");
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
echo $result;