@@ -14,20 +14,12 @@ class HttpGateway implements Gateway, HasHealthCheck
14
14
*/
15
15
public function dispatch (array $ page ): ?Response
16
16
{
17
- if (! config ('inertia.ssr.enabled ' , true )) {
18
- return null ;
19
- }
20
-
21
- if (! $ this ->shouldDispatchWithoutBundle () && ! $ this ->bundleExists ()) {
22
- return null ;
23
- }
24
-
25
- if (! $ url = $ this ->getUrl ('/render ' )) {
17
+ if (! $ this ->shouldDispatch ()) {
26
18
return null ;
27
19
}
28
20
29
21
try {
30
- $ response = Http::post ($ url , $ page )->throw ()->json ();
22
+ $ response = Http::post ($ this -> getUrl ( ' /render ' ) , $ page )->throw ()->json ();
31
23
} catch (Exception $ e ) {
32
24
if ($ e instanceof StrayRequestException) {
33
25
throw $ e ;
@@ -46,6 +38,22 @@ public function dispatch(array $page): ?Response
46
38
);
47
39
}
48
40
41
+ /**
42
+ * Determine if the page should be dispatched to the SSR engine.
43
+ */
44
+ protected function shouldDispatch (): bool
45
+ {
46
+ return $ this ->ssrIsEnabled () && ($ this ->shouldDispatchWithoutBundle () || $ this ->bundleExists ());
47
+ }
48
+
49
+ /**
50
+ * Determine if the SSR feature is enabled.
51
+ */
52
+ protected function ssrIsEnabled (): bool
53
+ {
54
+ return config ('inertia.ssr.enabled ' , true );
55
+ }
56
+
49
57
/**
50
58
* Determine if the SSR server is healthy.
51
59
*/
@@ -73,7 +81,7 @@ protected function bundleExists(): bool
73
81
/**
74
82
* Get the SSR URL from the configuration, ensuring it ends with '/{$path}'.
75
83
*/
76
- public function getUrl (string $ path ): ? string
84
+ public function getUrl (string $ path ): string
77
85
{
78
86
$ path = Str::start ($ path , '/ ' );
79
87
0 commit comments