File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Lecture13/express-middlewares Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ const express = require ( 'express' )
2
+ const app = express ( )
3
+
4
+ app . get ( '/favicon.ico' , ( req , res ) => {
5
+ res . sendStatus ( 404 )
6
+ } )
7
+
8
+ function m1 ( req , res , next ) {
9
+ console . log ( 'middleware 1 running' ) ;
10
+ next ( ) ;
11
+ }
12
+ function m2 ( req , res , next ) {
13
+ console . log ( 'middleware 2 running' ) ;
14
+ next ( ) ;
15
+ }
16
+ function m3 ( req , res , next ) {
17
+ console . log ( 'middleware 3 running' ) ;
18
+ next ( ) ;
19
+ }
20
+ function m4 ( req , res , next ) {
21
+ console . log ( 'middleware 4 running' ) ;
22
+ next ( ) ;
23
+ }
24
+
25
+ function m5 ( req , res ) {
26
+ console . log ( 'middleware 5 running' ) ;
27
+ res . send ( 'End' )
28
+ }
29
+
30
+ app . use ( '/a' , m1 )
31
+ app . use ( '/' , m2 )
32
+ app . use ( '/a/b' , m3 )
33
+ app . use ( '/a' , m4 )
34
+ app . use ( '/' , m5 )
35
+
36
+ app . listen ( 8787 )
You can’t perform that action at this time.
0 commit comments