Skip to content

Commit fe34947

Browse files
eypsilonclaude
andcommitted
Refactor to unified index.php entry point
- Rename example/index.html to example/index.php - Add PHP logic to handle both GET (HTML) and POST (API) requests - Update api/index.php to require example/index.php - Update vercel.json to route all requests to api/index.php - Remove duplicate api/get.php (using example/get.php instead) - Change fetch URL to window.location.pathname for universal routing - Update autoload path to use dirname(__DIR__) pattern - Matches proven Curler deployment pattern 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 51dc5dd commit fe34947

File tree

5 files changed

+20
-228
lines changed

5 files changed

+20
-228
lines changed

api/get.php

Lines changed: 0 additions & 222 deletions
This file was deleted.

api/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* Vercel API Entry Point
4-
* Routes requests to the example directory
4+
* Routes all requests to the example directory
55
*
66
* Requires PHP 8.1+ (vercel-php@0.7.4 uses PHP 8.2)
77
*/
@@ -17,4 +17,4 @@
1717
exit;
1818
}
1919

20-
require dirname(__DIR__) . '/example/get.php';
20+
require dirname(__DIR__) . '/example/index.php';

example/get.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
header('Content-Type: application/json');
1414

15-
require_once __DIR__ . '/../vendor/autoload.php';
15+
require_once dirname(__DIR__) . '/vendor/autoload.php';
1616

1717
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
1818
http_response_code(405);
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
<?php
2+
/**
3+
* php-ymap Demo - Unified Entry Point
4+
* Handles both HTML UI and AJAX API requests
5+
*/
6+
7+
// If this is a POST request, handle it as an API call
8+
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
9+
require __DIR__ . '/get.php';
10+
exit;
11+
}
12+
13+
// Otherwise, serve the HTML UI
14+
?>
115
<!DOCTYPE html>
216
<html lang="en">
317
<head>
@@ -633,7 +647,7 @@
633647

634648
.address-link {
635649
margin-left: 8px;
636-
max-width: 220px;
650+
max-width: 200px;
637651
display: inline-block;
638652
overflow: hidden;
639653
text-overflow: ellipsis;
@@ -1269,7 +1283,7 @@ <h3 style="margin-bottom: 0.5rem;">⚡ Powered by YEH</h3>
12691283
messagesContainer.style.display = 'none';
12701284

12711285
try {
1272-
const response = await fetch('./get.php', {
1286+
const response = await fetch(window.location.pathname, {
12731287
method: 'POST',
12741288
body: new FormData(form)
12751289
});

vercel.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
}
66
},
77
"routes": [
8-
{ "src": "/example/get.php", "dest": "/api/index.php" }
8+
{ "src": "/(.*)", "dest": "/api/index.php" }
99
]
1010
}

0 commit comments

Comments
 (0)