zoukankan      html  css  js  c++  java
  • 4.创建中间件

    创建自定义中间件

    提供一个 接受Request对象作为第一个参数,Response对象作为第二个参数,next作为第三个参数 的函数

    next()参数是一个通过中间件框架传递的函数,指向下一个要执行的中间件函数。所以必须在退出自定义函数之前调用next(),否则程序不会被调用

    var express=require('express');
    var app=express();
    function queryRemover(req,res,next){
    	console.log("
     Before URL: ");
    	console.log(req.url);
    	req.url=req.url.split('?')[0];
    	console.log("
     After URL: ");
    	console.log(req.url);
    	next();
    }
    app.use(queryRemover);
    app.get('/query',function(req,res){
    	res.send("test");
    })
    app.listen(8081);
    

      

  • 相关阅读:
    find the most comfortable road
    Rank of Tetris
    Segment set
    Codeforces Round #380 (Div. 2)D. Sea Battle
    A Bug's Life
    Is It A Tree?
    N皇后问题
    符号三角形
    2016 ICPC总结
    Sudoku Killer
  • 原文地址:https://www.cnblogs.com/weizaiyes/p/6062175.html
Copyright © 2011-2022 走看看