-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpressMiddleware3.js
46 lines (33 loc) · 1.3 KB
/
expressMiddleware3.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
const app= require('express')();
const logger= require('./testFiles/loggerForMiddleware');
const authorize= require('./testFiles/authorizeForMiddleware');
app.use([logger,authorize]); //Multiple middleware function use korar jonno array te likhte hoy. Order onujayee execute hobe.. prothome logger, tarpor authorize, order change korle notun order onujayee hobe.
app.get('/',(req,res)=>{
res.send('Home Page');
})
app.get('/about',(req,res)=>{
res.send('About Page');
})
/*
app.get('/api',[logger,authorize],(req,res)=>{ //ekta particular route e multiple middleware add korte chaile evabe array te dhokate hobe
res.send('Api Page');
})
*/
app.get('/api/products',(req,res)=>{
console.log(req.user); //authorize middleware ta diye je user add korechilam request object e, seta evabe access kora jay
res.send('Products Page');
})
app.get('/api/items',(req,res)=>{
res.send('Items Page');
})
app.listen(80,()=>{
console.log('Server is listening to port 80...');
})
/*---------------------
Types of Middleware
---------------------*/
/*
our own / express / third party
Example: express --> express.static (static files share korte use kora hoy,etao basically ekta middleware)
third party --> morgan
*/