diff --git a/config/plugin/webman/push/route.php b/config/plugin/webman/push/route.php index ea54c37..0b09191 100644 --- a/config/plugin/webman/push/route.php +++ b/config/plugin/webman/push/route.php @@ -17,10 +17,21 @@ use Webman\Route; use Webman\Push\Api; /** - * 推送js客户端文件 + * 推送 js 客户端 + * - 生产环境 Nginx 常把 root 指到 public/:须存在 public/plugin/webman/push/push.js(与 vendor 同步) + * - 若请求进入 Webman,则优先读 public,其次 vendor */ Route::get('/plugin/webman/push/push.js', function (Request $request) { - return response()->file(base_path().'/vendor/webman/push/src/push.js'); + $publicFile = public_path() . DIRECTORY_SEPARATOR . 'plugin' . DIRECTORY_SEPARATOR . 'webman' . DIRECTORY_SEPARATOR . 'push' . DIRECTORY_SEPARATOR . 'push.js'; + if (is_file($publicFile)) { + return response()->file($publicFile); + } + $vendorFile = base_path() . '/vendor/webman/push/src/push.js'; + if (is_file($vendorFile)) { + return response()->file($vendorFile); + } + + return response('push.js not found. Run: copy vendor/webman/push/src/push.js to public/plugin/webman/push/push.js', 404); }); /**