Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

Commit

Permalink
Added new before start check, when prerender host (option `server.pre…
Browse files Browse the repository at this point in the history
…render.host`) is fill and has a valid url address.
  • Loading branch information
roquie committed Jan 27, 2020
1 parent f5039e3 commit 5ebd7d1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## [2.0.3] - 2020-01-27

### Added

- Added new before start check, when prerender host (option `server.prerender.host`) is fill and has a valid url address.

### Changed

None.

### Removed

None.

## [2.0.2] - 2020-01-27

### Added
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Server created for javascript SPA apps like: Vue, React, Angular, etc.
## Docker usage

```Dockerfile
FROM microparts/static-server-php:2.0.2
FROM microparts/static-server-php:2.0.3

ARG VCS_SHA1
ARG STAGE
Expand All @@ -45,7 +45,7 @@ server run

Result:
```bash
[2019-12-18 17:38:30] Server.INFO: State: STAGE=local SHA1= VERSION=2.0.2 CONFIG_PATH=/Users/roquie/google_drive/projects/microparts/static-server-php/configuration
[2019-12-18 17:38:30] Server.INFO: State: STAGE=local SHA1= VERSION=2.0.3 CONFIG_PATH=/Users/roquie/google_drive/projects/microparts/static-server-php/configuration
[2019-12-18 17:38:30] Server.INFO: Files modification enabled. Have fun!.
[2019-12-18 17:38:30] Server.INFO: Nginx Brotli module not installed. Turning off this compression method.
[2019-12-18 17:38:30] Server.INFO: Check if platform supports async io...
Expand All @@ -68,7 +68,7 @@ server reload
Reload command result:
```bash
[2019-12-18 17:41:44] Server.INFO: Reload configuration
[2019-12-18 17:41:44] Server.INFO: State: STAGE=local SHA1= VERSION=2.0.2 CONFIG_PATH=/Users/roquie/google_drive/projects/microparts/static-server-php/configuration
[2019-12-18 17:41:44] Server.INFO: State: STAGE=local SHA1= VERSION=2.0.3 CONFIG_PATH=/Users/roquie/google_drive/projects/microparts/static-server-php/configuration
[2019-12-18 17:41:44] Server.INFO: Files modification enabled. Have fun!.
[2019-12-18 17:41:44] Server.INFO: Nginx Brotli module not installed. Turning off this compression method.
[2019-12-18 17:41:44] Server.INFO: Check if platform supports async io...
Expand Down
2 changes: 1 addition & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

final class Application
{
public const VERSION = '2.0.2';
public const VERSION = '2.0.3';
private const SERVER_LOG_CHANNEL = 'Server';

private Configuration $conf;
Expand Down
22 changes: 22 additions & 0 deletions src/Handler/NginxHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function checkDependenciesBeforeStart(): void
$this->checkIfBrotliModuleInstalled();
$this->checkIfPlatformSupportsAsyncIo();
$this->checkIfPrerenderUrlIsAvailable();
$this->checkIfPrerenderHostIsNotEmpty();
}

/**
Expand Down Expand Up @@ -198,6 +199,27 @@ private function checkIfPrerenderUrlIsAvailable(): void
$this->logger->warning('Prerender url could not be reached: ' . $url);
}

private function checkIfPrerenderHostIsNotEmpty(): void
{
if (!$this->configuration->get('server.prerender.enabled', false)) {
return;
}

$this->logger->info('Checks prerender host is fill and has a valid url address...');

$host = $this->configuration->get('server.prerender.host', '');

if (strlen($host) < 1) {
throw new InvalidArgumentException('Prerender host is empty. Check server.prerender.host config key.');
}

$valid = (bool) parse_url($host);

if (!$valid) {
throw new InvalidArgumentException('Prerender host is invalid (can\'t parse a url). Check server.prerender.host config key.');
}
}

/**
* @return void
*/
Expand Down
1 change: 1 addition & 0 deletions src/Handler/templates/nginx_default.conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@
#setting prerender as a variable forces DNS resolution since nginx caches IPs and doesnt play well with load balancing
rewrite .* /<?=$prerenderHost?>$request_uri?$query_string break;
proxy_pass "<?=$prerenderUrl?>";
break;
}

if ($prerender = 0) {
Expand Down

0 comments on commit 5ebd7d1

Please sign in to comment.