Skip to content

Commit

Permalink
Create default site route. Warn if no default or multiple defaults ar…
Browse files Browse the repository at this point in the history
…e set
  • Loading branch information
omahm committed Oct 5, 2022
1 parent 5d47394 commit 53a6397
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/Provider/PlatformSH.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function build(StyleInterface $io, FilesystemInterface $fs, ProjectInterf
// Flag to determine if we need to include Solr configuration
// in the Platform services file.
$solr_required = FALSE;
$default_site_entries = 0;

$platform = $fs->read($this->resourcesPath() . '/templates/.platform.app.template.yaml');
$services = $fs->read($this->resourcesPath() . '/templates/.services.template.yaml');
Expand Down Expand Up @@ -69,9 +70,25 @@ public function build(StyleInterface $io, FilesystemInterface $fs, ProjectInterf
$platform['crons'][$site_id]['cmd'] = $site['cron_cmd'];
}

// Create development instance route.
if ($site['status'] !== 'production') {
// Create Platform SH route.
// Create routes.
if ($site['default'] === true) {
$default_site_entries++;
// Create Platform SH route for the default site.
$routes['https://www.' . $site['url'] . '.{default}/'] = [
'type' => 'upstream',
'upstream' => $platform['name'] . ':http',
'cache' => [
'enabled' => 'false',
],
];

$routes['https://' . $site['url'] . '.{default}/'] = [
'type' => 'redirect',
'to' => 'https://www.' . $site['url'] . '.{default}/',
];
}
elseif ($site['status'] !== 'production' && $site['default'] !== true) {
// Create routes for dev sites.
$routes['https://www.' . $site['url'] . '/'] = [
'type' => 'upstream',
'upstream' => $platform['name'] . ':http',
Expand Down Expand Up @@ -127,6 +144,14 @@ public function build(StyleInterface $io, FilesystemInterface $fs, ProjectInterf
$io->writeln('Copying Redis install script.');
$fs->copy($this->resourcesPath() . '/files/install-redis.sh', '/install-redis.sh');

// Warn if we have no default site or more than one defined.
if ($default_site_entries === 0) {
$io->warning("This project does not have a default site enabled.");
}
elseif ($default_site_entries > 1) {
$io->warning("This project has multiple sites designated as the default site.");
}

$this->addInstructions('Download PlatformSH databases: platform db:dump -p ' . $project->id());
$this->addInstructions('Download PlatformSH files: platform mount:download -p ' . $project->id());
}
Expand Down

0 comments on commit 53a6397

Please sign in to comment.