diff options
author | Mark Powers <markppowers0@gmail.com> | 2019-01-27 13:56:59 -0500 |
---|---|---|
committer | Mark Powers <markppowers0@gmail.com> | 2019-01-27 13:56:59 -0500 |
commit | a16648b1af583e16e43b421bcd980ddcef304b51 (patch) | |
tree | 0ad38138dc12e35beaa0ed6659b6c62818be30d7 /src/server.js | |
parent | 6825b445ad975d603b4c212aed85f86559642e0f (diff) |
Refactor bread to use vue.js
Diffstat (limited to 'src/server.js')
-rw-r--r-- | src/server.js | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/server.js b/src/server.js index a487af5..c94a91c 100644 --- a/src/server.js +++ b/src/server.js @@ -9,7 +9,7 @@ function listen(){ server.listen(port, () => console.info(`Listening on port ${port}!`)); } -function setUpRoutes(){ +function setUpRoutes(models){ server.get('/', (req, res) => res.sendFile(__dirname + "/html/index.html")) server.get('/bread', (req, res) => res.sendFile(__dirname + "/html/bread.html")); server.get('/essay', (req, res) => res.sendFile(__dirname + "/html/essay.html")); @@ -18,6 +18,20 @@ function setUpRoutes(){ request(`http://localhost:8000?${req.url.split("?")[1]}`, function(error, response, body) { }); }) + server.get('/posts.json', async (req, res, next) => { + try { + var posts = await models.posts.findAll(); + posts = posts.map(x => x.get({ plain: true })); + for (const post of posts) { + const images = await models.pictures.findAll({ attributes: ["source"], where: { postId: post.id } }).map(x => x.source); + post.images = images; + } + res.status(200).send({ success: true, data: posts }); + next(); + } catch (e) { + res.status(400).send({ success: false, error: e.message }); + } + }) server.get('/favicon.ico', (req, res) => res.sendFile(__dirname + "/icon/favicon.ico")) |