-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (32 loc) · 858 Bytes
/
index.js
File metadata and controls
38 lines (32 loc) · 858 Bytes
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
const express = require('express');
const app = express();
const about = express();
const middleWareHandle =(obj)=>{
return (req,res,next)=>{
if(obj.isLogin){
console.log(`${new Date(Date.now()).toLocaleString()} - ${req.method} - ${req.path} - ${req.protocol}`);
next();
}
else{
throw new Error('Error Founds');
}
}
}
app.use('/about',about);
about.use(middleWareHandle({'isLogin': false}));
app.get('/home',(req,res)=>{
res.send('hello');
console.log(req.url);
})
const errorHandle = (err,req,res,next)=>{
console.log(err.message);
res.status(404).send('there is a error');
}
about.use(errorHandle);
about.get('/aboutHandle',(req,res,next)=>{
console.log('hello boy');
res.end();
})
app.listen(3000,()=>{
console.log('Running at port 3000');
});