I'm developing an app in PHP + ReactJs, I have created a script tag, and for that I have created one JS file, outside of the project, and called it to my controller file.
<?php
public function StCreate(Request $request)
{
$shopDomain = "xyz.myshopify.com";
$accessToken = "shpat_0dfe2de8c1c791sdsdsda9a8e2c7a2de9a5901";
// Set the script tag properties
$scriptTag = [
'event' => 'onload',
'src' => 'https://www.abcd.in/upload/custom.js'
];
// Create the script tag using the Shopify API
$response = Http::withHeaders([
'X-Shopify-Access-Token' => $accessToken,
'Content-Type' => 'application/json'
])->post("https://{$shopDomain}/admin/api/2023-04/script_tags.json", [
'script_tag' => $scriptTag,
'display_scope' => 'cart'
]);
return $response->json();
}
now I'm trying to add one API in that outside custom.js custom.js code
fetch('/api/get-saved-form-data')
.then(response => response.json())
.then(formData => {
console.log('Hello World...');
})
.catch(error => {
console.error('Error fetching form data:', error);
});
but in Shopify, im Run the App using Cloudflare tunnel, and this tunnel is every time new generate when we Run the app, using the command 'npm run dev' now problem is, I tried to run my API in outside js from the project, using the above custom.js code. in this fetch function "fetch('/api/get-saved-form-data')" this API create URL
like..https://xyz.myshopify.com/api/get-saved-form-data (this is the Shopify actual URL) but actually, URLs made like https://tunnel-url/api/get-saved-form-data
that was not created. so how can I add that tunnel URL here?
please help me with this.
Thanks.