mirror of
https://github.com/namibia/awesome-cheatsheets.git
synced 2024-12-22 10:08:54 +00:00
HTTP App Routes
This commit is contained in:
parent
b9be6c4cbc
commit
8008c44d49
@ -119,4 +119,43 @@ app.use('<admin dir>', admin)`; // Mounting a sub - app
|
||||
|
||||
`admin.on('mount', (parent){
|
||||
console.log('Admin Mounted')
|
||||
})` //
|
||||
})` // Mounting on a parent app
|
||||
|
||||
``Methods``
|
||||
`app.get('/', function(req, res){
|
||||
res.send('GET request to message')
|
||||
})` // get requests to the specified path
|
||||
|
||||
`app.post('/', function(req,res){
|
||||
res.send('POST request to a webpage')
|
||||
})`
|
||||
|
||||
`app.put('/', function(req,res){
|
||||
res.send('PUT request to a webpage')
|
||||
})`
|
||||
|
||||
`app.delete('/', function(req,res){
|
||||
res.send('DELETE request to a webpage')
|
||||
})`
|
||||
|
||||
`app.all('/', function(req,res,next){
|
||||
console.log('Accessing the secret section....')
|
||||
next()
|
||||
})`
|
||||
|
||||
`app.param('user', function(req,res,next){
|
||||
User.find(id, function(err, user){
|
||||
if(err){
|
||||
next(err)
|
||||
} else if (user){
|
||||
req.user = user
|
||||
next()
|
||||
} else {
|
||||
next(new Error('Failed to load user'))
|
||||
}
|
||||
})
|
||||
})`
|
||||
|
||||
`app.use(function(req,res,next){
|
||||
res.send('Hey There!')
|
||||
})`
|
Loading…
Reference in New Issue
Block a user