Skip to content

Commit 13bde7e

Browse files
committed
Added support for Inertia SSR start daemon and stop command
1 parent 3be0aca commit 13bde7e

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

app/Commands/ProvisionCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use App\Services\Forge\Pipeline\AnnounceSiteOnSlack;
1818
use App\Services\Forge\Pipeline\CreateDatabase;
1919
use App\Services\Forge\Pipeline\DeploySite;
20+
use App\Services\Forge\Pipeline\EnableInertiaSupport;
2021
use App\Services\Forge\Pipeline\EnableQuickDeploy;
2122
use App\Services\Forge\Pipeline\EnsureJobScheduled;
2223
use App\Services\Forge\Pipeline\FindServer;
@@ -60,6 +61,7 @@ public function handle(ForgeService $service): void
6061
EnsureJobScheduled::class,
6162
PutCommentOnPullRequest::class,
6263
AnnounceSiteOnSlack::class,
64+
EnableInertiaSupport::class,
6365
])
6466
->then(function () use ($service) {
6567
$this->success('Provisioning complete! Your environment is now set up and ready to use.');
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of Laravel Harbor.
7+
*
8+
* (c) Mehran Rasulian <[email protected]>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace App\Services\Forge\Pipeline;
15+
16+
use App\Services\Forge\ForgeService;
17+
use App\Traits\Outputifier;
18+
use Closure;
19+
20+
class EnableInertiaSupport
21+
{
22+
use Outputifier;
23+
24+
public function __invoke(ForgeService $service, Closure $next)
25+
{
26+
if (! $service->setting->inertiaSsrEnabled) {
27+
return $next($service);
28+
}
29+
30+
if (! $service->siteNewlyMade) {
31+
return $next($service);
32+
}
33+
34+
$this->addDaemonToStartInertiaSsr($service);
35+
36+
$this->addCommandToStopInertiaOnReDeploy($service);
37+
38+
return $next($service);
39+
}
40+
41+
protected function addDaemonToStartInertiaSsr(ForgeService $service): void
42+
{
43+
$this->information('Create a daemon for Inertia.js SSR.');
44+
45+
$service->forge->createDaemon($service->server->id, [
46+
'command' => 'php artisan inertia:start-ssr',
47+
'user' => 'forge',
48+
'directory' => $service->siteDirectory()
49+
]);
50+
}
51+
52+
protected function addCommandToStopInertiaOnReDeploy(ForgeService $service): void
53+
{
54+
$script = $service->forge->siteDeploymentScript($service->server->id, $service->site->id);
55+
56+
if (!str_contains($script, $command = 'php artisan inertia:stop-ssr')) {
57+
$this->information('Including stop command for Inertia SSR in deploy script.');
58+
59+
$service->forge->updateSiteDeploymentScript(
60+
$service->server->id,
61+
$service->site->id,
62+
$script . "\n\n$command"
63+
);
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)