-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: macdonst <[email protected]>
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default function FourOhFour ({ html, state }) { | ||
const { error } = state.attrs | ||
|
||
return html` | ||
<main> | ||
<h1>Custom 404</h1> | ||
<h2>Sorry we can't find that.</h2> | ||
<p>${error && error}</p> | ||
</main> | ||
` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import test from 'tape' | ||
import url from 'url' | ||
import path from 'path' | ||
import router from '../src/http/any-catchall/router.mjs' | ||
|
||
const __dirname = path.dirname(url.fileURLToPath(import.meta.url)) | ||
|
||
test('test default 404 page', async t => { | ||
t.plan(2) | ||
let req = { | ||
rawPath: '/nope', | ||
method: 'GET', | ||
headers: { | ||
'accept': 'text/html' | ||
} | ||
} | ||
let base = path.join(__dirname, 'mock-folders', 'app') | ||
let result = await router({ basePath: base }, req) | ||
t.ok(result, 'got result') | ||
t.equal(result.status, 404, 'Default 404 page') | ||
console.log(result) | ||
}) | ||
|
||
test('overridden 404 page', async t => { | ||
t.plan(2) | ||
let req = { | ||
rawPath: '/nope', | ||
method: 'GET', | ||
headers: { | ||
'accept': 'text/html' | ||
} | ||
} | ||
let base = path.join(__dirname, 'mock-errors', 'app') | ||
let result = await router({ basePath: base }, req) | ||
t.ok(result.html.includes('Custom 404'), 'got result') | ||
t.equal(result.status, 404, 'Overridden 404 page') | ||
console.log(result) | ||
}) |