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

Commit 5ebd7d1

Browse files
committed
Added new before start check, when prerender host (option server.prerender.host) is fill and has a valid url address.
1 parent f5039e3 commit 5ebd7d1

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## [2.0.3] - 2020-01-27
2+
3+
### Added
4+
5+
- Added new before start check, when prerender host (option `server.prerender.host`) is fill and has a valid url address.
6+
7+
### Changed
8+
9+
None.
10+
11+
### Removed
12+
13+
None.
14+
115
## [2.0.2] - 2020-01-27
216

317
### Added

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Server created for javascript SPA apps like: Vue, React, Angular, etc.
2222
## Docker usage
2323

2424
```Dockerfile
25-
FROM microparts/static-server-php:2.0.2
25+
FROM microparts/static-server-php:2.0.3
2626

2727
ARG VCS_SHA1
2828
ARG STAGE
@@ -45,7 +45,7 @@ server run
4545

4646
Result:
4747
```bash
48-
[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
48+
[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
4949
[2019-12-18 17:38:30] Server.INFO: Files modification enabled. Have fun!.
5050
[2019-12-18 17:38:30] Server.INFO: Nginx Brotli module not installed. Turning off this compression method.
5151
[2019-12-18 17:38:30] Server.INFO: Check if platform supports async io...
@@ -68,7 +68,7 @@ server reload
6868
Reload command result:
6969
```bash
7070
[2019-12-18 17:41:44] Server.INFO: Reload configuration
71-
[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
71+
[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
7272
[2019-12-18 17:41:44] Server.INFO: Files modification enabled. Have fun!.
7373
[2019-12-18 17:41:44] Server.INFO: Nginx Brotli module not installed. Turning off this compression method.
7474
[2019-12-18 17:41:44] Server.INFO: Check if platform supports async io...

src/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
final class Application
2424
{
25-
public const VERSION = '2.0.2';
25+
public const VERSION = '2.0.3';
2626
private const SERVER_LOG_CHANNEL = 'Server';
2727

2828
private Configuration $conf;

src/Handler/NginxHandler.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function checkDependenciesBeforeStart(): void
6161
$this->checkIfBrotliModuleInstalled();
6262
$this->checkIfPlatformSupportsAsyncIo();
6363
$this->checkIfPrerenderUrlIsAvailable();
64+
$this->checkIfPrerenderHostIsNotEmpty();
6465
}
6566

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

202+
private function checkIfPrerenderHostIsNotEmpty(): void
203+
{
204+
if (!$this->configuration->get('server.prerender.enabled', false)) {
205+
return;
206+
}
207+
208+
$this->logger->info('Checks prerender host is fill and has a valid url address...');
209+
210+
$host = $this->configuration->get('server.prerender.host', '');
211+
212+
if (strlen($host) < 1) {
213+
throw new InvalidArgumentException('Prerender host is empty. Check server.prerender.host config key.');
214+
}
215+
216+
$valid = (bool) parse_url($host);
217+
218+
if (!$valid) {
219+
throw new InvalidArgumentException('Prerender host is invalid (can\'t parse a url). Check server.prerender.host config key.');
220+
}
221+
}
222+
201223
/**
202224
* @return void
203225
*/

src/Handler/templates/nginx_default.conf.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@
287287
#setting prerender as a variable forces DNS resolution since nginx caches IPs and doesnt play well with load balancing
288288
rewrite .* /<?=$prerenderHost?>$request_uri?$query_string break;
289289
proxy_pass "<?=$prerenderUrl?>";
290+
break;
290291
}
291292

292293
if ($prerender = 0) {

0 commit comments

Comments
 (0)