66use App \Models \Application ;
77use Illuminate \Support \Collection ;
88use Livewire \Component ;
9+ use Spatie \Url \Url ;
910use Visus \Cuid2 \Cuid2 ;
1011
1112class General extends Component
@@ -183,9 +184,7 @@ public function instantSave()
183184 $ storage ->save ();
184185 });
185186 }
186-
187187 }
188-
189188 }
190189
191190 public function loadComposeFile ($ isInit = false )
@@ -242,23 +241,6 @@ public function updatedApplicationBaseDirectory()
242241 }
243242 }
244243
245- public function updatedApplicationFqdn ()
246- {
247- try {
248- $ this ->application ->fqdn = str ($ this ->application ->fqdn )->replaceEnd (', ' , '' )->trim ();
249- $ this ->application ->fqdn = str ($ this ->application ->fqdn )->replaceStart (', ' , '' )->trim ();
250- $ this ->application ->fqdn = str ($ this ->application ->fqdn )->trim ()->explode (', ' )->map (function ($ domain ) {
251- return str ($ domain )->trim ()->lower ();
252- });
253- $ this ->application ->fqdn = $ this ->application ->fqdn ->unique ()->implode (', ' );
254- $ this ->application ->save ();
255- } catch (\Throwable $ e ) {
256- $ originalFqdn = $ this ->application ->getOriginal ('fqdn ' );
257- $ this ->application ->fqdn = $ originalFqdn ;
258- return handleError ($ e , $ this );
259- }
260- $ this ->resetDefaultLabels ();
261- }
262244
263245 public function updatedApplicationBuildPack ()
264246 {
@@ -332,7 +314,7 @@ public function checkFqdns($showToaster = true)
332314 public function set_redirect ()
333315 {
334316 try {
335- $ has_www = collect ($ this ->application ->fqdns )->filter (fn ($ fqdn ) => str ($ fqdn )->contains ('www. ' ))->count ();
317+ $ has_www = collect ($ this ->application ->fqdns )->filter (fn ($ fqdn ) => str ($ fqdn )->contains ('www. ' ))->count ();
336318 if ($ has_www === 0 && $ this ->application ->redirect === 'www ' ) {
337319 $ this ->dispatch ('error ' , 'You want to redirect to www, but you do not have a www domain set.<br><br>Please add www to your domain list and as an A DNS record (if applicable). ' );
338320
@@ -349,15 +331,18 @@ public function set_redirect()
349331 public function submit ($ showToaster = true )
350332 {
351333 try {
352- if ($ this ->application ->isDirty ('redirect ' )) {
353- $ this ->set_redirect ();
354- }
355334 $ this ->application ->fqdn = str ($ this ->application ->fqdn )->replaceEnd (', ' , '' )->trim ();
356335 $ this ->application ->fqdn = str ($ this ->application ->fqdn )->replaceStart (', ' , '' )->trim ();
357336 $ this ->application ->fqdn = str ($ this ->application ->fqdn )->trim ()->explode (', ' )->map (function ($ domain ) {
337+ Url::fromString ($ domain , ['http ' , 'https ' ]);
358338 return str ($ domain )->trim ()->lower ();
359339 });
360340 $ this ->application ->fqdn = $ this ->application ->fqdn ->unique ()->implode (', ' );
341+ $ this ->resetDefaultLabels ();
342+
343+ if ($ this ->application ->isDirty ('redirect ' )) {
344+ $ this ->set_redirect ();
345+ }
361346
362347 $ this ->checkFqdns ();
363348
@@ -420,6 +405,10 @@ public function submit($showToaster = true)
420405 $ this ->application ->save ();
421406 $ showToaster && $ this ->dispatch ('success ' , 'Application settings updated! ' );
422407 } catch (\Throwable $ e ) {
408+ $ originalFqdn = $ this ->application ->getOriginal ('fqdn ' );
409+ if ($ originalFqdn !== $ this ->application ->fqdn ) {
410+ $ this ->application ->fqdn = $ originalFqdn ;
411+ }
423412 return handleError ($ e , $ this );
424413 } finally {
425414 $ this ->dispatch ('configurationChanged ' );
0 commit comments