-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvan.js
77 lines (54 loc) · 1.26 KB
/
advan.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// var express = require('express');
// var app = express();
// var server = app.listen(3000)
// app.use(function (req, res, next) {
// console.log('Time:', Date.now())
// next()
// })
// app.use('/user/:id', function (req, res, next) {
// console.log('Request Type:', req.method)
// next()
// })
// app.get('/user/:id', function (req, res, next) {
// res.send('USER')
// })
const App = () => {
let req;
let res;
let pipeline = [];
const use = middleware => pipeline.push(middleware)
const runMiddlewares = () => {
if (clone.length !== 0) {
const xuly = pipeline .shift()
xuly(req, res, () => runMiddlewares())
}
}
function get() {
runMiddlewares()
}
return {use, get}
}
const app = App()
app.use((req, res, next) => {
console.log('Middleware 1')
next()
})
app.use((req, res, next) => {
console.log('Middleware 2 ')
next()
})
app.use((req, res, next) => {
console.log('Middleware 3')
next()
})
app.use((req, res, next) => {
console.log('Middleware 4')
next()
})
app.use((req, res, next) => {
console.log('Middleware 5')
})
app.use((req, res, next) => {
console.log('Middleware 6')
})
app.get()