2
2
3
3
namespace Inertia \Commands ;
4
4
5
+ use Inertia \Ssr \SsrException ;
5
6
use Illuminate \Console \Command ;
7
+ use Inertia \Ssr \BundleDetector ;
6
8
use Symfony \Component \Process \Process ;
7
9
8
10
class StartSsr extends Command
@@ -26,19 +28,36 @@ class StartSsr extends Command
26
28
*/
27
29
public function handle (): int
28
30
{
29
- $ ssrBundle = config ('inertia.ssr.bundle ' , base_path ('bootstrap/ssr/ssr.mjs ' ));
31
+ $ bundle = (new BundleDetector ())->detect ();
32
+ $ configuredBundle = config ('inertia.ssr.bundle ' );
30
33
31
- if (! file_exists ($ ssrBundle )) {
32
- $ this ->error ('Inertia SSR bundle not found: ' .$ ssrBundle );
33
- $ this ->info ('Set the correct Inertia SSR bundle path in your `inertia.ssr.bundle` config. ' );
34
+ if ($ bundle === null ) {
35
+ $ this ->error (
36
+ $ configuredBundle
37
+ ? 'Inertia SSR bundle not found at the configured path: " ' .$ configuredBundle .'" '
38
+ : 'Inertia SSR bundle not found. Set the correct Inertia SSR bundle path in your `inertia.ssr.bundle` config. '
39
+ );
34
40
35
41
return self ::FAILURE ;
42
+ } elseif ($ configuredBundle && $ bundle !== $ configuredBundle ) {
43
+ $ this ->warn ('Inertia SSR bundle not found at the configured path: " ' .$ configuredBundle .'" ' );
44
+ $ this ->warn ('Using a default bundle instead: " ' .$ bundle .'" ' );
36
45
}
37
46
38
- $ process = new Process (['node ' , $ ssrBundle ]);
47
+ $ this ->callSilently ('inertia:stop-ssr ' );
48
+
49
+ $ process = new Process (['node ' , $ bundle ]);
39
50
$ process ->setTimeout (null );
40
51
$ process ->start ();
41
52
53
+ $ stop = function () use ($ process ) {
54
+ $ process ->stop ();
55
+ };
56
+ pcntl_async_signals (true );
57
+ pcntl_signal (SIGINT , $ stop );
58
+ pcntl_signal (SIGQUIT , $ stop );
59
+ pcntl_signal (SIGTERM , $ stop );
60
+
42
61
foreach ($ process as $ type => $ data ) {
43
62
if ($ process ::OUT === $ type ) {
44
63
$ this ->info (trim ($ data ));
0 commit comments