Skip to content

Commit

Permalink
Add 404 page
Browse files Browse the repository at this point in the history
  • Loading branch information
ptoffy committed Jul 22, 2024
1 parent 8999f71 commit 2fba46f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Content/error/404.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Error 404 - Page not found

The page you are looking for might have been removed, had it's name changed or is temporarily unavailable.
Please try again later.

[Return to the home page](https://blog.vapor.codes)
4 changes: 1 addition & 3 deletions Sources/Website/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ struct MainSite: Website {

try MainSite().publish(using: [
.copyResources(),
// Here we remove the default .addMarkdownFiles()
// since we don't need to add any markdown files
// and can therefore remove the Content folder
.addMarkdownFiles(),
.generateHTML(withTheme: .vaporMainSite),
])
13 changes: 13 additions & 0 deletions stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ Resources:
BucketName: !Ref 'S3BucketName'
WebsiteConfiguration:
IndexDocument: index.html
# Redirect
ErrorDocument: /error/404/index.html
RoutingRules:
- RoutingRuleCondition:
HttpErrorCodeReturnedEquals: '404'
KeyPrefixEquals: /
RedirectRule:
HostName: !Ref 'DomainName'
ReplaceKeyPrefixWith: error/404/
WebsiteCloudfront:
Type: AWS::CloudFront::Distribution
Properties:
Expand All @@ -36,6 +45,10 @@ Resources:
Aliases:
- !Ref 'DomainName'
- !Sub 'www.${DomainName}'
CustomErrorResponses:
- ErrorCode: 403
ResponseCode: 404
ResponsePagePath: '/error/404/index.html'
DefaultCacheBehavior:
AllowedMethods:
- GET
Expand Down

0 comments on commit 2fba46f

Please sign in to comment.