diff --git a/routes/api/blog-posts.js b/routes/blog.json.js similarity index 100% rename from routes/api/blog-posts.js rename to routes/blog.json.js diff --git a/routes/blog/[slug].html b/routes/blog/[slug].html index 2646930..96c4699 100644 --- a/routes/blog/[slug].html +++ b/routes/blog/[slug].html @@ -59,7 +59,7 @@ // is called [slug].html const { slug } = params; - return fetch(`/api/blog/${slug}`).then(r => r.json()).then(post => { + return fetch(`/blog/${slug}.json`).then(r => r.json()).then(post => { return { post }; }); } diff --git a/routes/api/blog/[slug].js b/routes/blog/[slug].json.js similarity index 93% rename from routes/api/blog/[slug].js rename to routes/blog/[slug].json.js index f1a151f..33fc51e 100644 --- a/routes/api/blog/[slug].js +++ b/routes/blog/[slug].json.js @@ -7,7 +7,7 @@ posts.forEach(post => { export function get(req, res, next) { // the `slug` parameter is available because this file - // is called [slug].js + // is called [slug].json.js const { slug } = req.params; if (lookup.has(slug)) { diff --git a/routes/api/blog/_posts.js b/routes/blog/_posts.js similarity index 96% rename from routes/api/blog/_posts.js rename to routes/blog/_posts.js index 0864315..9e1ac88 100644 --- a/routes/api/blog/_posts.js +++ b/routes/blog/_posts.js @@ -4,7 +4,7 @@ // service of obviousness, we're just going to leave it here. // This file is called `_posts.js` rather than `posts.js`, because -// we don't want to create an `/api/blog/posts` route — the leading +// we don't want to create an `/blog/posts` route — the leading // underscore tells Sapper not to do that. const posts = [ @@ -70,7 +70,7 @@ const posts = [
routes/blog/[slug].htmlroutes directory. These are just .js files that export functions corresponding to HTTP methods, and receive Express request and response objects as arguments. This makes it very easy to, for example, add a JSON API such as the one powering this very page (look in routes/api/blog-posts)routes directory. These are just .js files that export functions corresponding to HTTP methods, and receive Express request and response objects as arguments. This makes it very easy to, for example, add a JSON API such as the one powering this very page<a> elements, rather than framework-specific <Link> components. That means, for example, that this link right here, despite being inside a blob of HTML, works with the router as you'd expect.