Skip to content

Instantly share code, notes, and snippets.

@natmegs

natmegs/htmlController.js

Last active Aug 26, 2017
Embed
What would you like to do?
htmlController for second express example
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
You can’t perform that action at this time.