[英]Express js delegate http verbs
我已經在Express應用程序的以下行中設置了一個斷點。
app.get('/api/post/:id', api.post);
當我進入該函數時,它將轉到:
/**
* Delegate `.VERB(...)` calls to `.route(VERB, ...)`.
*/
methods.forEach(function(method){
app[method] = function(path){
if (1 == arguments.length) return this.routes.lookup(method, path);
var args = [method].concat(toArray(arguments));
if (!this.__usedRouter) this.use(this.router);
return this.routes._route.apply(this.routes, args);
}
});
誰能解釋發生了什么事? 它如何以及為什么直接針對這段代碼?
代碼的發布位是app.get
函數的內容聲明。
methods
將是一個動詞數組( get
, post
, put
等),每個動詞都在app
上聲明為一個函數。
我假設您真正感興趣的是api.post
函數。 要檢查該函數,您必須在該函數中放置一個斷點,或者在該行上進入apply
this.routes._route.apply(this.routes, args);
看看接下來會發生什么。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.