Browse Source

Added api route

pull/99/head
jrtechs 4 years ago
parent
commit
84f4c33fb6
1 changed files with 24 additions and 0 deletions
  1. +24
    -0
      routes/api/index.js

+ 24
- 0
routes/api/index.js View File

@ -3,6 +3,30 @@ const sql = require('../../utils/sql');
const renderPost = require('../../blog/renderBlogPost'); const renderPost = require('../../blog/renderBlogPost');
routes.get('/getPostsIds/:category', (request, result) =>
{
if(request.params.category.length !== 1 &&
request.params.category.length !== 2)
{
result.json("boo").end();
return;
}
sql.getPostIds(request.params.category).then((sqlData)=>
{
var arr = [];
for(var i = 5; i < sqlData.length; i++)
{
arr.push(sqlData[i].post_id)
}
result.json(arr).end();
}).catch((err)=>
{
result.status(404).json({error: 404}).end();
})
});
routes.get('/posts', (request, result) => routes.get('/posts', (request, result) =>
{ {
sql.getAllPosts().then((data)=> sql.getAllPosts().then((data)=>

Loading…
Cancel
Save