Skip to content

Commit

Permalink
adding cdn file postfix param for prerender (#2)
Browse files Browse the repository at this point in the history
* adding cdn file postfix param for prerender
  • Loading branch information
smgladkovskiy authored May 25, 2020
1 parent 8e35e1b commit 3148f1e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## [3.1.1] - 2020-05-22

### Added

* Prerender cdn file postfix that is adding through config param.

### Changed

None.

### Removed

None.

## [3.1.0] - 2020-05-21

### Added
Expand Down
1 change: 1 addition & 0 deletions configuration/defaults/___server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ defaults:
queryParams: [] # params that will be passed to CDN to find files. Params are sorted alphabetically.
cdnUrl: null # CDN url
cdnPath: / # CDN folder relative to root path with trailing slash (/)
cdnFilePostfix: null
url: null # Proxy pass URL for bots, with schema.
resolver: "8.8.8.8 8.8.4.4 1.1.1.1 1.0.0.1" # nginx "resolver" option to force DNS resolution and prevent caching of IPs
headers: [] # Authorization headers (or others), format: key - $headerName, value - $headerValue
Expand Down
5 changes: 3 additions & 2 deletions src/Handler/NginxHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function generateConfig(HeaderInterface $header): void
'prerenderQueryParams' => $this->getSorted('server.prerender.queryParams'),
'CDNUrl' => $this->getParamWithoutTrailingSlash('server.prerender.cdnUrl'),
'CDNPath' => $this->getParamWithoutTrailingSlash('server.prerender.cdnPath'),
'CDNFilePostfix' => $this->configuration->get('server.prerender.cdnFilePostfix', null),
'prerenderHeaders' => $this->configuration->get('server.prerender.headers', []),
'prerenderResolver' => $this->configuration->get('server.prerender.resolver', false),
'headers' => $header->convert($this->configuration),
Expand Down Expand Up @@ -159,8 +160,8 @@ private function getParamWithoutTrailingSlash(string $key)
}

/**
* @param string $key
* @param array<mixed> $default
* @param string $key
* @param array<mixed> $default
*
* @return bool|string
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Handler/templates/nginx_default.conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
<?php endif;?>
if ($prerender = 1) {
#setting prerender as a variable forces DNS resolution since nginx caches IPs and doesnt play well with load balancing
rewrite .* <?=$CDNPath?>$req_uri$q break;
rewrite .* <?= $CDNPath ?>$req_uri$q<?= ($CDNFilePostfix) ? "-" . $CDNFilePostfix : null ?> break;
proxy_pass "<?=$CDNUrl?>";
break;
}
Expand Down

0 comments on commit 3148f1e

Please sign in to comment.