Skip to content

Commit

Permalink
redirection manual test put back
Browse files Browse the repository at this point in the history
Should be the only manual test we have now. Not sure how to automate.
  • Loading branch information
joshbruce committed Oct 28, 2021
1 parent 34ab10d commit e224d00
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
15 changes: 9 additions & 6 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@
exit;
}

// TESTING: Redirection
// Check browser address becomes /design-your-life
// if ($server->requestUri() !== '/design-your-life') {
// $_SERVER['REQUEST_URI'] = '/self-improvement';
// $server = JoshBruce\Site\Server::init($_SERVER);
// }

$content = $content->for($server->filePathForRequest());
if ($content->notFound()) {
$content = $content->for(path: '/.errors/404.md');
Expand Down Expand Up @@ -123,18 +130,14 @@
exit;
}

/**
* Target file wants to redirect us: local response time 40ms
*/
$redirectPath = $content->redirectPath();
if (strlen($redirectPath) > 0) {
if ($content->hasMoved()) {
$scheme = $_SERVER['REQUEST_SCHEME'];
$serverName = $_SERVER['HTTP_HOST'];
$requestDomain = $scheme . '://' . $serverName;
JoshBruce\Site\Emitter::emitWithResponse(
301,
[
'Location' => $requestDomain . $redirectPath
'Location' => $requestDomain . $content->redirectPath()
]
);
exit;
Expand Down
5 changes: 5 additions & 0 deletions src/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public function notFound(): bool
return ! $this->exists();
}

public function hasMoved(): bool
{
return strlen($this->redirectPath()) > 0;
}

public function filePath(): string
{
return $this->root() . $this->path;
Expand Down
2 changes: 1 addition & 1 deletion src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function filePathForRequest(): string
return $this->requestUri() . '/content.md';
}

private function requestUri(): string
public function requestUri(): string
{
if ($this->serverGlobals['REQUEST_URI'] === '/') {
return '';
Expand Down

0 comments on commit e224d00

Please sign in to comment.