فهرست منبع

Updated serve extension, better troubleshooting

markseu 3 سال پیش
والد
کامیت
8ece563c01
2فایلهای تغییر یافته به همراه23 افزوده شده و 12 حذف شده
  1. 21 10
      system/extensions/serve.php
  2. 2 2
      system/extensions/update-current.ini

+ 21 - 10
system/extensions/serve.php

@@ -2,7 +2,7 @@
 // Serve extension, https://github.com/datenstrom/yellow-extensions/tree/master/source/serve
 
 class YellowServe {
-    const VERSION = "0.8.18";
+    const VERSION = "0.8.19";
     public $yellow;         // access to API
     
     // Handle initialisation
@@ -30,15 +30,21 @@ class YellowServe {
         if (empty($url)) $url = "http://localhost:8000";
         list($scheme, $address, $base) = $this->yellow->lookup->getUrlInformation($url);
         if ($scheme=="http" && !empty($address)) {
-            if (!preg_match("/\:\d+$/", $address)) $address .= ":8000";
-            echo "Starting built-in web server. Open a web browser and go to $scheme://$address/\n";
-            echo "Press Ctrl+C to quit...\n";
-            exec("php -S $address yellow.php 2>&1", $outputLines, $returnStatus);
-            $statusCode = $returnStatus!=0 ? 500 : 200;
-            if ($statusCode!=200) {
-                $output = !empty($outputLines) ? end($outputLines) : "Please check arguments!";
-                if (preg_match("/^\[(.*?)\]\s*(.*)$/", $output, $matches)) $output = $matches[2];
-                echo "ERROR starting web server: $output\n";
+            if ($this->checkServerSettings()) {
+                if (!preg_match("/\:\d+$/", $address)) $address .= ":8000";
+                echo "Starting built-in web server. Open a web browser and go to $scheme://$address/\n";
+                echo "Press Ctrl+C to quit...\n";
+                exec("php -S $address yellow.php 2>&1", $outputLines, $returnStatus);
+                $statusCode = $returnStatus!=0 ? 500 : 200;
+                if ($statusCode!=200) {
+                    $output = !empty($outputLines) ? end($outputLines) : "Please check arguments!";
+                    if (preg_match("/^\[(.*?)\]\s*(.*)$/", $output, $matches)) $output = $matches[2];
+                    echo "ERROR starting web server: $output\n";
+                }
+            } else {
+                $statusCode = 400;
+                $fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreSystemFile");
+                echo "ERROR starting web server: Please configure `CoreServerUrl: auto` in file '$fileName'!\n";
             }
         } else {
             $statusCode = 400;
@@ -46,4 +52,9 @@ class YellowServe {
         }
         return $statusCode;
     }
+    
+    // Check server settings
+    public function checkServerSettings() {
+        return $this->yellow->system->get("coreServerUrl")=="auto";
+    }
 }

+ 2 - 2
system/extensions/update-current.ini

@@ -106,11 +106,11 @@ Tag: feature
 system/extensions/meta.php: meta.php, create, update
 
 Extension: Serve
-Version: 0.8.18
+Version: 0.8.19
 Description: Built-in web server.
 HelpUrl: https://github.com/datenstrom/yellow-extensions/tree/master/source/serve
 DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/master/zip/serve.zip
-Published: 2022-03-18 11:03:27
+Published: 2022-04-16 21:28:27
 Developer: Datenstrom
 Tag: feature
 system/extensions/serve.php: serve.php, create, update