Skip to content

Commit d8aa9b5

Browse files
committed
refactor: remove post contents from the payload when querying all
1 parent 3d84426 commit d8aa9b5

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

api/posts.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ export default async function (req, res) {
55
const posts = await postLoader.getMappedByName()
66
const postName = req.url.replace('/', '')
77
if (!postName) {
8-
const allPosts = []
9-
for (const post of Object.values(posts)) {
10-
allPosts.push(post)
11-
}
8+
const allPosts = Object
9+
.values(posts)
10+
.map(post => ({ ...post, contents: undefined }))
1211
return res.writeHead(200, { 'Content-Type': 'application/json' })
1312
.end(JSON.stringify(sortBy(prop('createdAt'), allPosts)))
1413
}
15-
14+
1615
const post = posts[postName]
1716
if (!post) {
1817
return res.writeHead(404).end()

0 commit comments

Comments
 (0)