Last active
August 26, 2017 21:52
-
-
Save natmegs/43b44d0735d0d05686cc9dd3638cd18f to your computer and use it in GitHub Desktop.
htmlController for second express example
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
var bodyParser = require('body-parser'); | |
var urlencodedParser = bodyParser.urlencoded({ extended: false }); | |
var jsonParser = bodyParser.json(); | |
module.exports = function(app) { | |
// This contains all of the endpoints that return views/html. | |
// The function takes an app object and adds the endpoints | |
// to the app. | |
app.get('/', function(req, res) { | |
res.send('<html><head><link href=assets/style.css type=text/css rel=stylesheet /></head><body><h1>Donuts</h1></body></html>'); | |
}); | |
app.get('/form', function(req, res){ | |
res.sendFile(__dirname + '/form.htm'); | |
}); | |
app.get('/person/:id', function(req, res) { | |
res.send('<html><head></head><body><h1>Donuts for Person ' + req.params.id + '</h1></body></html>'); | |
}); | |
app.post('/person', urlencodedParser, function(req, res){ | |
res.send('Thank you!'); | |
console.log(req.body.firstname); | |
console.log(req.body.lastname); | |
}); | |
app.post('/personjson', jsonParser, function(req, res){ | |
res.send('Thankyou for the json data'); | |
console.log(req.body.firstname); | |
console.log(req.body.lastname); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment