File tree Expand file tree Collapse file tree 1 file changed +30
-13
lines changed
Expand file tree Collapse file tree 1 file changed +30
-13
lines changed Original file line number Diff line number Diff line change 11<?php
2- // 设置返回为 JSON
3- // http://127.0.0.1:9980/config.php
42header ('Content-Type: application/json; charset=utf-8 ' );
5-
6- // 当前目录
7- $ dir = __DIR__ ;
8-
9- // 当前脚本名
3+ // http://127.0.0.1:9980/config.php
4+ // ==================
5+ // 1. 生成 sites
6+ // ==================
7+ $ dir = __DIR__ ;
108$ self = basename (__FILE__ );
11-
12- // 扫描目录
139$ files = scandir ($ dir );
1410
1511$ sites = [];
1612
1713foreach ($ files as $ file ) {
18- // 只处理 php 文件
1914 if (pathinfo ($ file , PATHINFO_EXTENSION ) !== 'php ' ) {
2015 continue ;
2116 }
2217
23- // 排除自身和 index.php
2418 if ($ file === $ self || $ file === 'index.php ' ) {
2519 continue ;
2620 }
2721
28- // 文件名(不含 .php)
2922 $ filename = pathinfo ($ file , PATHINFO_FILENAME );
3023
3124 $ sites [] = [
3932 ];
4033}
4134
42- // 输出 JSON
35+ // ==================
36+ // 2. 尝试加载 ../drpy-node/index.json
37+ // ==================
38+ $ indexJsonPath = realpath ($ dir . '/../drpy-node/index.json ' );
39+
40+ if ($ indexJsonPath && is_file ($ indexJsonPath )) {
41+ $ content = file_get_contents ($ indexJsonPath );
42+ $ json = json_decode ($ content , true );
43+
44+ // JSON 合法并且是数组
45+ if (is_array ($ json )) {
46+ // 替换 sites
47+ $ json ['sites ' ] = $ sites ;
48+
49+ echo json_encode (
50+ $ json ,
51+ JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT
52+ );
53+ exit ;
54+ }
55+ }
56+
57+ // ==================
58+ // 3. 找不到或失败,回退只返回 sites
59+ // ==================
4360echo json_encode (
4461 ["sites " => $ sites ],
4562 JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT
You can’t perform that action at this time.
0 commit comments