Skip to content

Commit

Permalink
proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
strukturart committed Dec 12, 2024
1 parent 650009e commit 038dd96
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 13 deletions.
4 changes: 2 additions & 2 deletions application/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ if (userAgent && userAgent.includes("KAIOS")) {
}

let current_article = "";
const proxy = "https://corsproxy.io/?";
const proxy = "https://api.cors.lol/?url=";

let default_settings = {
"opml_url":
"https://raw.githubusercontent.com/strukturart/feedolin/master/example.opml",
"opml_local": "",
"proxy_url": "https://corsproxy.io/?",
"proxy_url": "https://api.cors.lol/?url=",
"cache_time": 1000,
};
//store all articles id to compare
Expand Down
4 changes: 1 addition & 3 deletions application/manifest.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@
],

"b2g_features": {
"version": "1.8.128",
"version": "1.8.129",
"id": "feedolin",
"subtitle": "RSS Reader and Mastodon Reader",
"core": true,
"type": "privileged",
"display": "fullscreen",
"origin": "http://feedolin.localhost",

"developer": {
"name": "strukturart",
"url": "https://github.com/strukturart/feedolin"
Expand Down
2 changes: 1 addition & 1 deletion application/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ self.addEventListener("systemmessage", async (evt) => {
const userAgent = navigator.userAgent || "";

if (userAgent && !userAgent.includes("KAIOS")) {
const CACHE_NAME = "pwa-cache-v0.1181";
const CACHE_NAME = "pwa-cache-v0.1185";
const FILE_LIST_URL = "/file-list.json"; // URL of the JSON file containing the array of files

self.addEventListener("install", (event) => {
Expand Down
2 changes: 1 addition & 1 deletion docs/index.339e55c4.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.f0337e49.js

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions docs/manifest.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
],

"b2g_features": {
"version": "1.8.125",
"version": "1.8.129",
"id": "feedolin",
"subtitle": "RSS Reader and Mastodon Reader",
"core": true,
Expand Down Expand Up @@ -58,9 +58,7 @@
"desktop-notification": {
"description": "Needed to fire system notifications"
},
"alarms": {
"description": "Required to schedule alarms"
},

"feature-detection": {
"description": "query which keys are available"
},
Expand Down
2 changes: 1 addition & 1 deletion docs/sw.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions proxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
// Enable CORS
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Headers: Origin, Content-Type, Authorization, X-Requested-With");

// Parse input data
$requestBody = file_get_contents("php://input");
$isJsonRequest = false;
$requestData = json_decode($requestBody, true);
if (json_last_error() === JSON_ERROR_NONE) {
$isJsonRequest = true;
}

// Determine request parameters
$method = $_REQUEST['method'] ?? 'GET'; // Default to GET if method is not provided
$url = $isJsonRequest ? $requestData['cors'] ?? null : ($_REQUEST['cors'] ?? null);

// Handle direct query string URL (e.g., ?https://rss.strukturart.com/...)
if (!$url && isset($_SERVER['QUERY_STRING']) && filter_var($_SERVER['QUERY_STRING'], FILTER_VALIDATE_URL)) {
$url = $_SERVER['QUERY_STRING'];
}

if (!$url) {
echo json_encode(["message" => "PROXY ACCESS DENIED! URL not specified"]);
exit();
}

// Prepare headers
$headers = [];
foreach (getallheaders() as $key => $value) {
if (in_array(strtolower($key), ['content-type', 'authorization', 'x-requested-with'])) {
$headers[] = "$key: $value";
}
}

// Prepare CURL options
$curl = curl_init();
switch (strtoupper($method)) {
case 'POST':
$postData = $isJsonRequest ? $requestData : $_POST;
unset($postData['method'], $postData['cors']);
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $isJsonRequest ? json_encode($postData) : http_build_query($postData),
]);
break;

case 'GET':
$getData = $isJsonRequest ? $requestData : $_GET;
unset($getData['method'], $getData['cors']);
$queryString = http_build_query($getData);
curl_setopt($curl, CURLOPT_URL, $url . ($queryString ? "?$queryString" : ""));
break;

default:
echo json_encode(["message" => "Proxy only supports POST and GET requests"]);
exit();
}

curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false, // Disable for development, enable in production
CURLOPT_HTTPHEADER => $headers,
]);

// Execute CURL request
$response = curl_exec($curl);
$error = curl_error($curl);
curl_close($curl);

if ($error) {
echo json_encode(["error" => $error]);
exit();
}

// Set response content type if possible
if (json_decode($response) !== null) {
header('Content-Type: application/json');
} elseif (strpos($response, '<?xml') === 0) {
header('Content-Type: application/xml');
}

// Output the response
echo $response;

0 comments on commit 038dd96

Please sign in to comment.