-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa4950c
commit 089a5c1
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const express = require('express'); | ||
const app = express(); | ||
|
||
|
||
//creating a middleware | ||
const reqFilters = (req , res , next) => { | ||
if(!req.query.age){ | ||
res.send('<h1>Please Provide Age</h1>'); | ||
} | ||
|
||
else if(req.query.age < 18){ | ||
res.send('<h1>You can not access this page</h1>'); | ||
} | ||
|
||
else{ | ||
next(); | ||
} | ||
} | ||
|
||
app.get('/' , (req,res) => { | ||
res.send('<h1>Welcome to home page</h1>'); | ||
}); | ||
|
||
|
||
//appliying middleware on single route | ||
app.get('/user' , reqFilters , (req , res) => { | ||
res.send('<h1>Welcome to users page</h1>') | ||
}); | ||
|
||
app.listen(8000 , (err) => { | ||
if(!err){ | ||
console.log('Server is running on the port::8000'); | ||
} | ||
}); |