快速应用程序使用 [英] Express app.use

查看:66
本文介绍了快速应用程序使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读文档/URL,但真的不了解app.use及其用法. 我知道这是连接的一部分,但我确实没有得到.

I have been reading documents/urls and really not understand about app.use and its usage. I understand that it is part of connect but I am really not getting that.

示例:

// ignore GET /favicon.ico
app.use(express.favicon());
// add req.session cookie support
app.use(express.cookieSession());
// do something with the session
app.use(count);

您能给我解释一下所有这3个吗?他们是什么意思? 这是否意味着基于(1) app.use在注意,但=> app.get? app.use(count)执行此计数的时间和时间(或)称为/

can you please explain me all these 3 . what they mean? does this mean based on (1) that app.use is noting but => app.get? app.use(count) what and when is this count be executed (or) called/

看起来很基本,但是没有得到答案

Looks Basic but did not get the answers

// ignore GET /favicon.ico
app.use(express.favicon());

// pass a secret to cookieParser() for signed cookies 
app.use(express.cookieParser('manny is cool'));

// add req.session cookie support
app.use(express.cookieSession());

// do something with the session
app.use(count);

// custom middleware
function count(req, res) {

推荐答案

调用app.use()时,您传入一个函数来处理请求.随着请求的到来,Express依次处理所有功能,直到处理完请求为止.

When you call app.use(), you pass in a function to handle requests. As requests come in, Express goes through all of the functions in order until the request is handled.

express.favicon是一个简单函数,在被请求时返回favicon.ico.实际上,这是一个很好的示例,说明了如何开始使用此模式.您可以通过查看源代码来查看源代码:node_modules/express/node_modules/connect/lib/middleware/favicon.js

express.favicon is a simple function that returns favicon.ico when it is requested. It's actually a great example for how to get started with this pattern. You can view the source code by looking at its source: node_modules/express/node_modules/connect/lib/middleware/favicon.js

express.cookieSession是更多用于支持会话数据的中间件,这些中间件通过cookie从客户端输入.

express.cookieSession is some more middleware for supporting session data, keyed from the client by a cookie.

我不知道count是什么...这是您自己的代码吗?无论如何,请让我知道是否不清楚.

I don't know what count does... is that your own code? In any case, let me know if this is not clear.

这篇关于快速应用程序使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆