簡體   English   中英

Express JS委托HTTP動詞

[英]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將是一個動詞數組( getpostput等),每個動詞都在app上聲明為一個函數。

我假設您真正感興趣的是api.post函數。 要檢查該函數,您必須在該函數中放置一個斷點,或者在該行上進入apply this.routes._route.apply(this.routes, args); 看看接下來會發生什么。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM