-
-
Save wbobeirne/f6f43fbeb815b03598fd41110357928e to your computer and use it in GitHub Desktop.
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
import postsManager from './posts'; | |
// Routes | |
app.get('/api/posts', (req, res) => { | |
res.json({ data: postsManager.getPaidPosts() }); | |
}); | |
app.get('/api/posts/:id', (req, res) => { | |
const post = postsManager.getPost(parseInt(req.params.id, 10)); | |
if (post) { | |
res.json({ data: post }); | |
} else { | |
res.status(404).json({ error: `No post found with ID ${req.params.id}`}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment