mirror of
https://github.com/kevin-DL/sapper-template.git
synced 2026-01-19 13:05:18 +00:00
replace 4xx and 5xx with _error, per 0.14
This commit is contained in:
@@ -1,22 +0,0 @@
|
|||||||
<svelte:head>
|
|
||||||
<title>Internal server error</title>
|
|
||||||
</svelte:head>
|
|
||||||
|
|
||||||
<h1>Internal server error</h1>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
h1 {
|
|
||||||
text-align: center;
|
|
||||||
margin: 0 auto;
|
|
||||||
font-size: 2.8em;
|
|
||||||
text-transform: uppercase;
|
|
||||||
font-weight: 700;
|
|
||||||
margin: 0 0 0.5em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (min-width: 480px) {
|
|
||||||
h1 {
|
|
||||||
font-size: 4em;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,20 +1,18 @@
|
|||||||
<svelte:head>
|
<svelte:head>
|
||||||
<title>Not found</title>
|
<title>{status}</title>
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<h1>Not found</h1>
|
<h1>{status}</h1>
|
||||||
|
|
||||||
<p>Please check the URL</p>
|
<p>{error.message}</p>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
h1, p {
|
h1, p {
|
||||||
text-align: center;
|
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
font-size: 2.8em;
|
font-size: 2.8em;
|
||||||
text-transform: uppercase;
|
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
margin: 0 0 0.5em 0;
|
margin: 0 0 0.5em 0;
|
||||||
}
|
}
|
||||||
@@ -46,14 +46,17 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
preload({ params, query }) {
|
async preload({ params, query }) {
|
||||||
// the `slug` parameter is available because this file
|
// the `slug` parameter is available because
|
||||||
// is called [slug].html
|
// this file is called [slug].html
|
||||||
const { slug } = params;
|
const res = await this.fetch(`blog/${params.slug}.json`);
|
||||||
|
const data = await res.json();
|
||||||
|
|
||||||
return this.fetch(`blog/${slug}.json`).then(r => r.json()).then(post => {
|
if (res.status === 200) {
|
||||||
return { post };
|
return { post: data };
|
||||||
});
|
} else {
|
||||||
|
this.error(res.status, data.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@@ -6,8 +6,8 @@ posts.forEach(post => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export function get(req, res, next) {
|
export function get(req, res, next) {
|
||||||
// the `slug` parameter is available because this file
|
// the `slug` parameter is available because
|
||||||
// is called [slug].json.js
|
// this file is called [slug].json.js
|
||||||
const { slug } = req.params;
|
const { slug } = req.params;
|
||||||
|
|
||||||
if (lookup.has(slug)) {
|
if (lookup.has(slug)) {
|
||||||
@@ -17,6 +17,12 @@ export function get(req, res, next) {
|
|||||||
|
|
||||||
res.end(lookup.get(slug));
|
res.end(lookup.get(slug));
|
||||||
} else {
|
} else {
|
||||||
next();
|
res.writeHead(404, {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
});
|
||||||
|
|
||||||
|
res.end(JSON.stringify({
|
||||||
|
message: `Not found`
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user