new posts
This commit is contained in:
@@ -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!")
|
||||
|
||||
Reference in New Issue
Block a user