new posts

This commit is contained in:
Adolfo Reyna
2021-07-23 22:04:33 -07:00
parent 43df66efab
commit 6904ad913e
5 changed files with 117 additions and 7 deletions
+22 -2
View File
@@ -29,6 +29,9 @@ const getUserId = function(req){
return user_sid
}
// Definitions
const Post = require("./def/post.js")
DB.getDB.then((DB)=>{
// middleware function to check for logged-in users
@@ -78,8 +81,8 @@ DB.getDB.then((DB)=>{
maxAge: 1000 * 60 * 60 * 24 * 30, // would expire after 30 days
httpOnly: true, // The cookie only accessible by the web server
//signed: true // Indicates if the cookie should be signed
sameSite: 'none',
secure: true,
sameSite: 'none', // This and secure are required for properly
secure: true, // manage cockies in cros-domain
};
// route for user Login
@@ -129,6 +132,23 @@ DB.getDB.then((DB)=>{
return logout(req, res);
});
app.get("/post/", sessionChecker, async (req, res) => {
let posts = await DB.getPosts();
return res.json(posts)
});
app.get("/post/new", sessionChecker, async (req, res) => {
let post = {
userid: getUserId(req),
content: req.query.content
}
let postObj = new Post(post);
DB.newPost(postObj)
return res.json({
status: "ok"
})
})
// route for handling 404 requests(unavailable routes)
app.use(function (req, res, next) {
res.status(404).send("Sorry can't find that!")