Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. var express = require('express')
  2.  
  3. var app = express()
  4.  
  5. app.use(function (req, res, next) {
  6. console.log(1)
  7. next()
  8. })
  9.  
  10. app.get('/abc', function (req, res, next) {
  11. console.log('abc')
  12. next()
  13. })
  14.  
  15. app.get('/', function (req, res, next) {
  16. console.log('/')
  17. next()
  18. })
  19.  
  20. app.use(function (req, res, next) {
  21. console.log('haha')
  22. next()
  23. })
  24.  
  25. app.get('/abc', function (req, res, next) {
  26. console.log('abc 2')
  27. })
  28.  
  29. app.use(function (req, res, next) {
  30. console.log(2)
  31. next()
  32. })
  33.  
  34. app.get('/a', function (req, res, next) {
  35. console.log('/a')
  36. })
  37.  
  38. app.get('/', function (req, res, next) {
  39. console.log('/ 2')
  40. })
  41.  
  42. // 如果没有能匹配的中间件,则 Express 会默认输出:Cannot GET 路径
  43.  
  44.  
  45. app.listen(3000, function () {
  46. console.log('app is running at port 3000.')
  47. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement