Skip to content

Commit

Permalink
feat: 404 page for /hoodie/* resource URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
jamietanna authored and gr2m committed Jan 8, 2017
1 parent c8fea9a commit 823562e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 12 additions & 0 deletions public/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hoodie</title>

<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>Error 404: Not Found</h1>
</body>
</html>
8 changes: 4 additions & 4 deletions server/plugins/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ function register (server, options, next) {
}

var is404 = response.output.statusCode === 404
var isHTML = /text\/html/.test(request.headers.accept)
var isResource = /(text\/css|application\/json|application\/javascript|image\/png|image\/jpeg)/.test(request.headers.accept) || /.(css|js|png|jpg)$/.test(request.path)
var isAccountPath = /^\/hoodie\/account\//.test(request.path)
var isAdminPath = /^\/hoodie\/admin\//.test(request.path)
var isStorePath = /^\/hoodie\/store\//.test(request.path)
var isHoodiePath = /^\/hoodie\//.test(request.path)

// We only care about 404 for html requests...
if (!is404 || !isHTML) {
return reply.continue()
if (is404 && isResource) {
return reply(fs.createReadStream(path.join(hoodiePublicPath, '404.html'))).code(404)
}

if (isAccountPath) {
Expand All @@ -115,7 +115,7 @@ function register (server, options, next) {
return reply(fs.createReadStream(path.join(storePublicPath, 'index.html')))
}
if (isHoodiePath) {
return reply.continue()
return reply(fs.createReadStream(path.join(hoodiePublicPath, 'index.html')))
}

// Serve index.html
Expand Down

0 comments on commit 823562e

Please sign in to comment.