Skip to content

Commit

Permalink
Merge pull request #9 from 8fold/working
Browse files Browse the repository at this point in the history
bad gateway (502) seemed inappropriate
  • Loading branch information
joshbruce authored Oct 28, 2021
2 parents ec49f32 + 9daa5ed commit 523d0b8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
11 changes: 2 additions & 9 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
);

if ($content->folderIsMissing()) {
JoshBruce\Site\Emitter::emitBadGatewayResponse(
JoshBruce\Site\Emitter::emitBadContentResponse(
$markdownConverter,
$projectRoot
);
Expand All @@ -71,14 +71,7 @@
}

if ($server->isRequestingFile()) {
JoshBruce\Site\Emitter::emitWithResponseFile(
200,
[
'Cache-Control' => ['max-age=2592000'],
'Content-Type' => $content->mimeType()
],
$content->filePath()
);
JoshBruce\Site\Emitter::emitFile($content->mimeType(), $content->filePath());
exit;
}

Expand Down
4 changes: 2 additions & 2 deletions setup-errors/502.md → setup-errors/500_2.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: Content error
title: Server error
usage: The folder containing the site content could not be located.
---

# 502: Bad gateway (content)
# 500: Server error (content)

We're not sure what happened here but we're pretty sure it's on us.

Expand Down
16 changes: 14 additions & 2 deletions src/Emitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ public static function emit(PsrResponse $response): void
$emitter->emit($response);
}

public static function emitFile(string $mimeType, string $filePath): void
{
self::emitWithResponseFile(
200,
[
'Cache-Control' => ['max-age=2592000'],
'Content-Type' => $mimeType
],
$filePath
);
}

public static function emitInterServerErrorResponse(
Markdown $converter,
string $projectRoot
Expand Down Expand Up @@ -98,12 +110,12 @@ public static function emitUnsupportedMethodResponse(
);
}

public static function emitBadGatewayResponse(
public static function emitBadContentResponse(
Markdown $converter,
string $projectRoot
): void {
$content = Content::init($projectRoot, 0, '/setup-errors')
->for('/502.md');
->for('/500.md');

self::emitWithResponse(
502,
Expand Down

0 comments on commit 523d0b8

Please sign in to comment.