From c84ae160ef42b24e04b3ace6e301cc7d425e4e59 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 5 Feb 2018 09:09:32 -0500 Subject: [PATCH] make project exportable by avoiding api/blog route conflict --- routes/api/{blog/index.js => blog-posts.js} | 2 +- routes/api/blog/_posts.js | 2 +- routes/blog/index.html | 2 +- server.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename routes/api/{blog/index.js => blog-posts.js} (85%) diff --git a/routes/api/blog/index.js b/routes/api/blog-posts.js similarity index 85% rename from routes/api/blog/index.js rename to routes/api/blog-posts.js index 4c10788..7120e67 100644 --- a/routes/api/blog/index.js +++ b/routes/api/blog-posts.js @@ -1,4 +1,4 @@ -import posts from './_posts.js'; +import posts from './blog/_posts.js'; const contents = JSON.stringify(posts.map(post => { return { diff --git a/routes/api/blog/_posts.js b/routes/api/blog/_posts.js index 7fe65c5..0864315 100644 --- a/routes/api/blog/_posts.js +++ b/routes/api/blog/_posts.js @@ -70,7 +70,7 @@ const posts = [ ` diff --git a/routes/blog/index.html b/routes/blog/index.html index 16ff29e..70f17a8 100644 --- a/routes/blog/index.html +++ b/routes/blog/index.html @@ -32,7 +32,7 @@ }, preload({ params, query }) { - return fetch(`/api/blog`).then(r => r.json()).then(posts => { + return fetch(`/api/blog-posts`).then(r => r.json()).then(posts => { return { posts }; }); } diff --git a/server.js b/server.js index 5b46a61..cd79704 100644 --- a/server.js +++ b/server.js @@ -6,7 +6,7 @@ const static = require('serve-static'); const { PORT = 3000 } = process.env; -// this allows us to do e.g. `fetch('/api/blog')` on the server +// this allows us to do e.g. `fetch('/api/blog-posts')` on the server const fetch = require('node-fetch'); global.fetch = (url, opts) => { if (url[0] === '/') url = `http://localhost:${PORT}${url}`;