var app = express();
//for post
var bodyParser = require('body-parser');
var urlencodedParser = bodyParser.urlencoded({ extended: false })
app.use(express.static('public'));
app.get('/', function (req, res) {
res.send('Hello World');
});
app.get('/aboutus', function (req, res) {
console.log('Got a get request for About Us');
res.send('About Us');
});
app.get('/*list', function (req, res) {
console.log('Got a get request for for list');
res.send('Page listing');
});
app.get('/products/:productId', function (req, res) {
res.send("Request id " + req.params.productId);
});
app.get('/form', function (req, res) {
res.sendFile( __dirname + "/form.html");
})
app.get('/process_get', function (req, res) {
// Prepare output in JSON format
response = {
first_name:req.query.first_name,
last_name:req.query.last_name
};
console.log(response);
res.end(JSON.stringify(response))
});
app.post('/process_post', urlencodedParser, function (req, res) {
// Prepare output in JSON format
response = {
first_name:req.body.first_name,
last_name:req.body.last_name
};
console.log(response);
res.end(JSON.stringify(response))
});
var server = app.listen(1234, function () {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port);
});