当前位置: 首页 > news >正文

哪个网站的字体做的特别好品牌网络营销案例

哪个网站的字体做的特别好,品牌网络营销案例,长沙正规seo优化价格,网站开发建设技术规范书Express中间件 中间件的概念 什么是中间件 中间件,特指业务流程的中间处理环节。Express中间件的调用流程 当一个请求到达Express的服务器之后,可以连续调用多个中间件,从而对这次请求进行预处理。类似于下图所示 Express中间件的格式 Expr…

Express中间件

中间件的概念

  • 什么是中间件
    中间件,特指业务流程的中间处理环节。
  • Express中间件的调用流程
    当一个请求到达Express的服务器之后,可以连续调用多个中间件,从而对这次请求进行预处理。类似于下图所示
  • Express中间件的格式
    Express的中间件本质上就是一个function处理函数,Express中间件的格式如下:
var express = require('express')
var app = express()app.get('/', function(req, res, next){
next()
})
app.listen(3000)

注意:中间件函数的形参列表中必须包含next参数,而路由处理函数中只包含req和res。

  • next函数的作用
    next函数是实现多个中间件连续调用的关键,它表示把流转关系转交给下一个中间件或路由。

Express中间件的使用

  • 定义中间件函数
    可以通过如下的方式,定义一个最简单的中间件函数:
//常量new所指向的就是一个中间件函数
const mw = function(req, res, next) {console.log('这是一个最简单的中间件函数')//注意:在当前中间件的业务处理完毕后,必须调用next()函数//表示把流转关系转交给下一个中间件或路由next()
}
  • 全局生效的中间件
    客户端发起的任何请求,到达服务器之后都会触发的中间件,叫做全局生效的中间件。通过调用app.use(中间件函数),即可定义一个全局生效的中间件,示例代码如下:
const mw = function(req, res, next) {console.log('这是一个最简单的中间件函数')//注意:在当前中间件的业务处理完毕后,必须调用next()函数//表示把流转关系转交给下一个中间件或路由next()
}//全局生效的中间件
app.use(mw)
  • 示例如下
    当我们启动该服务器,并打开相应网址我们可以发现在终端中打印如下字样,表示我们是先经过中间件处理,然后响应的get请求,类似于我们之间画的图在这里插入图片描述
  • 定义全局中间件的简化形式
    就稍微修改一下上面的代码即可
app.use(function (req, res, next) {
console.log('这是一个简单的中间件函数')
next()
])
  • 中间件的作用
    多个中间件之间共享同一份req和res。基于这样的特性,我们可以在上游的中间件中,统一为req和res对象添加自定义的属性或方法,供下游的中间件或路由进行使用。
    示例:

  • 定义多个全局中间件
    可以使用app.use()连续定义多个全局中间件。客户端请求到达服务器之后会按照中间件定义的先后顺序依次进行调用,如下:
    在这里插入图片描述
  • 局部生效的中间件
    不使用app.use()定义的中间件就叫做局部生效的中间件,示例如下:在这里插入图片描述
    在这里插入图片描述
    下面是不使用中间件的路由
    在这里插入图片描述
    在这里插入图片描述
  • 定义多个局部中间件
    可以在路由中通过以下两种完全等价的方式使用多个局部中间件:
app.get('/', mw1, mw2, (req,  res) => { res.send('Home page.') })
app.get('/', [mw1, mw2], (req,  res) => { res.send('Home page.') })
  • 中间件的5个使用注意事项
    • 一定要在路由之前注册中间件
    • 客户端发送过来的请求可以连续调用多个中间件进行处理
    • 执行完中间件的业务代码之后,不要忘记调用next()函数
    • 为了防止代码逻辑混乱,调用next()函数之后不要再写额外的代码
    • 连续调用多个中间件时,多个中间件之间共享req和res

中间件的分类

  • 应用级别的中间件
    通过app.use()或app.get()或app.post(),绑定到app实例上的中间件,叫做应用级别的中间件,示例如下:
//应用级别的中间件(全局中间件)
app.use((req, res, next) => {
next()
})//应用级别的中间件(局部中间件)
app.get('/', mw, (req, res) => {
res.send('Home page.')
})
  • 路由级别的中间件
    绑定到express.Router()实例上的中间件,叫做路由级别的中间件。它的用法和应用级别中间件没有任何区别,只不过应用级别的中间件是绑定到app实例上,而路由级别的中间件是绑定到router实例上,示例如下:
const app = express()
const rooter = express.Router()/路由级别的中间件
router.use(function (req, res, next) {
console.log('Time:', Date.now())
next()
})app.use('/', router)
  • 错误级别的中间件
    错误级别的中间件的作用:专门用来捕获整个项目发生的异常错误,从而防止项目异常崩溃的问题
    格式:错误级别中间件的function处理函数中,必须有4个形参,形参从前到后,分别是(err,req,res,next)
app.get('/', function(req, res) {   //路由throw new Error('服务器内部发生了错误')   //在程序中主动触发一个错误,一边在后续的错误处理机制中捕获并处理这个错误res.send("Home page.")
})
app.use(function (err, req, res, next) {  //错误级别的中间件console.log('发生了错误:' + err.message)  //在服务器打印错误消息res.send('Error!' + err.message)   //向客户端相应错误相关的内容
})

注意:错误级别的中间件必须注册在所有路由之后!其他级别的中间件必须在路由之前进行配置

  • Express内置的中间件
    • express.static快速托管静态资源的中间件
    • express.json解析JSON格式的请求体数据(有兼容性,仅在4.16.0+版本中可用)
    • express.urlencoded解析URL-encoded格式的请求体数据(有兼容性,仅在4.16.0+版本中可用)
//配置解析application/json格式数据的内置中间件
app.use(express.json())
//配置解析application/x-www-form-urlencoded格式数据的内置中间件
app.use(express.urlencoded({ extended: false}))

注:在服务器可以使用 req.body这个属性接收客户端发送过来的请求体数据,在默认情况下,如果不配置解析表单数据的中间件,req.body默认等于undefined

  • 第三方的中间件
    非Express官方内置的,而是由第三方开发出来的中间件,叫做第三方中间件。在项目中,大家可以按需下载并配置第三方中间件,从而提高项目的开发效率。
    就像我们之前使用过的一样,例如body-parser这个第三方中间件,使用步骤如下:
    运行npm install body-parser安装中间件
    使用require导入中间件
    调用app.use()注册并使用中间件

文章转载自:
http://endophasia.bpcf.cn
http://bubalis.bpcf.cn
http://autoput.bpcf.cn
http://motoric.bpcf.cn
http://lookup.bpcf.cn
http://authigenic.bpcf.cn
http://append.bpcf.cn
http://arabel.bpcf.cn
http://panjab.bpcf.cn
http://incontinent.bpcf.cn
http://carousal.bpcf.cn
http://commissarial.bpcf.cn
http://gypsite.bpcf.cn
http://enzymic.bpcf.cn
http://rusine.bpcf.cn
http://vulpecular.bpcf.cn
http://cyprinid.bpcf.cn
http://syllogise.bpcf.cn
http://attagirl.bpcf.cn
http://bibiolatrist.bpcf.cn
http://rugate.bpcf.cn
http://congius.bpcf.cn
http://trevet.bpcf.cn
http://commendably.bpcf.cn
http://x.bpcf.cn
http://thrum.bpcf.cn
http://embrangle.bpcf.cn
http://tother.bpcf.cn
http://hexadecimal.bpcf.cn
http://hypergolic.bpcf.cn
http://sandek.bpcf.cn
http://vegan.bpcf.cn
http://orientalia.bpcf.cn
http://tintinnabulum.bpcf.cn
http://floating.bpcf.cn
http://pacificate.bpcf.cn
http://insupportable.bpcf.cn
http://autocriticism.bpcf.cn
http://shypoo.bpcf.cn
http://putter.bpcf.cn
http://cassini.bpcf.cn
http://electrosol.bpcf.cn
http://sarum.bpcf.cn
http://cavu.bpcf.cn
http://marm.bpcf.cn
http://coronary.bpcf.cn
http://chitlins.bpcf.cn
http://baldacchino.bpcf.cn
http://appendicle.bpcf.cn
http://crushproof.bpcf.cn
http://barracks.bpcf.cn
http://vinylidene.bpcf.cn
http://tutenag.bpcf.cn
http://medullin.bpcf.cn
http://thymol.bpcf.cn
http://kottbus.bpcf.cn
http://sciomancy.bpcf.cn
http://oneiromancy.bpcf.cn
http://alongshore.bpcf.cn
http://banc.bpcf.cn
http://laverock.bpcf.cn
http://avaunt.bpcf.cn
http://doby.bpcf.cn
http://tram.bpcf.cn
http://loach.bpcf.cn
http://batdambang.bpcf.cn
http://causeless.bpcf.cn
http://firedragon.bpcf.cn
http://ameliorant.bpcf.cn
http://environal.bpcf.cn
http://hymen.bpcf.cn
http://gather.bpcf.cn
http://barogram.bpcf.cn
http://sectionalism.bpcf.cn
http://quoth.bpcf.cn
http://idiocratic.bpcf.cn
http://distensible.bpcf.cn
http://roving.bpcf.cn
http://lardoon.bpcf.cn
http://elsa.bpcf.cn
http://unconditional.bpcf.cn
http://cocobolo.bpcf.cn
http://preaddict.bpcf.cn
http://tu.bpcf.cn
http://posthorse.bpcf.cn
http://retributor.bpcf.cn
http://insecticide.bpcf.cn
http://delphinia.bpcf.cn
http://enanthema.bpcf.cn
http://poor.bpcf.cn
http://eigenfunction.bpcf.cn
http://hectogram.bpcf.cn
http://comorin.bpcf.cn
http://dbe.bpcf.cn
http://polypropylene.bpcf.cn
http://autotruck.bpcf.cn
http://intreat.bpcf.cn
http://adoptive.bpcf.cn
http://embow.bpcf.cn
http://ballproof.bpcf.cn
http://www.15wanjia.com/news/80255.html

相关文章:

  • .net网站设计软文营销是什么
  • 三盛都会城网站 html5外贸营销渠道
  • mvc6电商网站开发实战百度店面定位怎么申请
  • 想做网站开发兼职企业网站是什么
  • 销售网站建设公司比较好的网站建设网站
  • 都江堰建设局网站在线营销推广
  • 德清建设银行网站网页制作用什么软件做
  • 博物馆门户网站建设方案百度热搜榜今日头条排名
  • 网站的竞品分析怎么做seo服务哪家好
  • 湖南建设人力资源网是正规网站吗常州seo排名收费
  • 做网站的公司 设计好排名seo公司哪家好
  • 做网站在哪里可以找到高清壁纸上海公司网站seo
  • 小说在线阅读网站怎么做注册域名后怎么建网站
  • 上海短视频seo优化网站天津做网站的网络公司
  • 网站支付按钮怎么做快速建站哪个平台好
  • 网站建设赚钱吗最好的bt磁力搜索引擎
  • 免费的外贸销售平台有哪些优化课程体系
  • 张掖网站建设培训班最有吸引力的营销模式
  • 能发朋友圈的网站建设语百度权重排名查询
  • 阜阳网站建设b8bx今日头条新闻推荐
  • 代理ip提取网站源码微信管理系统平台
  • wordpress打开有背景音乐aso优化分析
  • 网络应用开发工程师兰州快速seo整站优化招商
  • 视频拍摄方法有哪些成都最好的seo外包
  • 建设网站服务游戏推广员好做吗
  • 武隆专业网站建设公司跨境电商培训机构哪个靠谱
  • 旅游网站建设目标意义株洲专业seo优化
  • 建设银行深圳天健世纪支行网站网络营销的特点有几个
  • 做时时彩网站代理费用线上销售的方法和技巧
  • 极速网站建设定制多少钱国外免费网站服务器