@@ -14,20 +14,12 @@ class HttpGateway implements Gateway, HasHealthCheck
1414 */
1515 public function dispatch (array $ page ): ?Response
1616 {
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 ()) {
2618 return null ;
2719 }
2820
2921 try {
30- $ response = Http::post ($ url , $ page )->throw ()->json ();
22+ $ response = Http::post ($ this -> getUrl ( ' /render ' ) , $ page )->throw ()->json ();
3123 } catch (Exception $ e ) {
3224 if ($ e instanceof StrayRequestException) {
3325 throw $ e ;
@@ -46,6 +38,22 @@ public function dispatch(array $page): ?Response
4638 );
4739 }
4840
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+
4957 /**
5058 * Determine if the SSR server is healthy.
5159 */
@@ -73,7 +81,7 @@ protected function bundleExists(): bool
7381 /**
7482 * Get the SSR URL from the configuration, ensuring it ends with '/{$path}'.
7583 */
76- public function getUrl (string $ path ): ? string
84+ public function getUrl (string $ path ): string
7785 {
7886 $ path = Str::start ($ path , '/ ' );
7987
0 commit comments