progs/ap1.js
author Christian Urban <urbanc@in.tum.de>
Tue, 23 Aug 2016 15:37:59 +0200
changeset 460 ab7acd13bef3
parent 166 bba0504abcf0
permissions -rw-r--r--
updated

var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));

// sending the form
app.get('/', function(req, res){
    var html = '<form action="/" method="post">' +
        'Login:    <input type="text" name="login" /><br>' +
        'Password: <input type="password" name="pass" /><br>' + 
        '<button type="submit">Submit</button></form>';
    res.send(html);
});

// receiving data
app.post('/', function(req, res){
    var html = 'Received login: ' + req.body.login + '<br>' +
        'Received password: ' + req.body.pass + '<br>' +
        '<a href="/">Try again</a>';
    res.send(html);
});