Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions proxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');

// Handle preflight OPTIONS request
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit();
}

$apiUrl = 'https://map.meshcore.dev/api/v1/nodes';

// Initialize cURL
$ch = curl_init();

// Set the URL
curl_setopt($ch, CURLOPT_URL, $apiUrl);

// Set request method
$method = $_SERVER['REQUEST_METHOD'];
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);

// Set headers
$headers = [
'Content-Type: application/json',
'User-Agent: MeshCore Map Proxy'
];

// Forward request body for POST requests
if ($method === 'POST') {
$input = file_get_contents('php://input');
curl_setopt($ch, CURLOPT_POSTFIELDS, $input);
}

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

// Execute request
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

// Check for cURL errors
if (curl_error($ch)) {
http_response_code(500);
echo json_encode(['error' => 'Proxy error: ' . curl_error($ch)]);
curl_close($ch);
exit();
}

curl_close($ch);

// Set the HTTP response code
http_response_code($httpCode);

// Return the response
echo $response;
?>
2 changes: 1 addition & 1 deletion src/map.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createApp, reactive, ref, computed, watch, onMounted, toRaw } from '../lib/vue.esm-browser.js';
import * as ntools from './node-utils.js';
const apiUrl = 'https://map.meshcore.dev/api/v1/nodes';
const apiUrl = './proxy.php';

const types = {
'1': 'Client',
Expand Down