0
我想为一个网站建立一个评论部分,我希望每个评论都有一个基本上是domain.com/titles/postID/commentID的静态URL,其中postID是评论回复到的帖子的ID 。如何获取节点中当前页面的URL?
这里是我的代码:
exports.commentHandler = function(req, res){
comment = req.body.comment;
username = req.session.username;
buildpost.comment(comment, username)
};
这里的buildpost.comment:
exports.comment = function(comment, username){
var id = makeid(7);
var comment = {comment: comment, user: username, postID: id, type: "comment"}
console.log(comment);
postdb.write(comment);
};
这里是我的app.js文件中的相关代码:
app.get('/titles/:id', home.content); //this serves the post's page, where the comments are
app.post('/comment', home.commentHandler);
这里的玉石形式:
form.sbBox#commentReply(method='post', action='/comment')
如果我只是在exports.commentHandler中沿着这些行使用req.url或其他东西,它会返回'/ comment',这是发布请求的URL,而不是页面。
我不知道我跟随。我只是将当前的发布请求更改为那个?我是否也将我的玉石形式的那部分做出来?我会张贴更多的代码。 – user1816679
如果您忽略了
完美地工作,谢谢! – user1816679