2013-08-18 31 views
1

app.post未提供app.post(..)提供的獨特功能,但沒有記錄在expressjs.com中。據我所知,服務器監聽url requestion /等,然後調用中間件和回調。但所有這些在app.get中都是一樣的。Express.js

它提供了什麼獨特的價值來表達?

PS。還有其他問題,例如Express Framework app.post and app.getapp.use and app.get (or app.post) node.js express,但閱讀同一問題的答案不能提供問題的答案。

編輯:

下面的代碼爲雙方提供app.getapp.post的調用從browswer /login請求。是否調用app.getapp.post? (據推測,在出現的順序。)

app.get('/login', function(req, res){ 
var username = req.user ? req.user.username : ''; res.render('login', { title: 'authenticate', username: username, 
}); 
message: req.flash('error') }); 
app.post('/login', 
passport.authenticate('local', { failureRedirect: '/login', failureFlash: true }), function(req, res) { 
res.redirect('/admin'); }); 

enter code here 

回答

2

我不會說這是not documented,但基本上它一樣app.get()確實爲HTTP GET,而是隻匹配HTTP POST請求。

如果您不知道POSTGET之間的區別是什麼,您可以例如看看here

至於你的示例代碼,根據瀏覽器是發佈帖子還是獲取請求,調用你的get或post處理程序。兩者都不會針對同一個請求進行調用。

+0

您提供的'here'鏈接是指html 2.0標準。他們仍然適用? (在HTML 5中,世界)這似乎是一個很有用的鏈接。 – Swagg