Last active
January 14, 2024 08:44
-
-
Save heriniaina/6a70a50e27d9a20d2cdc463b5bdd01bf to your computer and use it in GitHub Desktop.
proxy php to forward request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Allow requests from any origin | |
header("Access-Control-Allow-Origin: *"); | |
// Replace 'YOUR_API_ENDPOINT' with the actual API endpoint | |
$apiEndpoint = 'https://sandipapi.onrender.com/gpt'; | |
// Get the prompt from the query parameters | |
$prompt = isset($_GET['prompt']) ? $_GET['prompt'] : ''; | |
// Construct the API request URL | |
$apiRequestUrl = $apiEndpoint . '?prompt=' . urlencode($prompt); | |
// Make the request to the external API | |
$response = file_get_contents($apiRequestUrl); | |
// Output the response as JSON | |
header('Content-Type: application/json'); | |
echo json_encode(['response' => $response]); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment