author | cu |
Mon, 09 Oct 2017 10:07:35 +0100 | |
changeset 547 | eae9a2e6ff28 |
parent 166 | bba0504abcf0 |
permissions | -rw-r--r-- |
166
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
var express = require('express'); |
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
var bodyParser = require('body-parser'); |
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
var app = express(); |
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
app.use(bodyParser.urlencoded({ extended: true })); |
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
|
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
6 |
// sending the form |
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
7 |
app.get('/', function(req, res){ |
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
var html = '<form action="/" method="post">' + |
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
9 |
'Login: <input type="text" name="login" /><br>' + |
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
10 |
'Password: <input type="password" name="pass" /><br>' + |
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
11 |
'<button type="submit">Submit</button></form>'; |
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
12 |
res.send(html); |
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
13 |
}); |
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
14 |
|
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
15 |
// receiving data |
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
16 |
app.post('/', function(req, res){ |
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
17 |
var html = 'Received login: ' + req.body.login + '<br>' + |
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
18 |
'Received password: ' + req.body.pass + '<br>' + |
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
19 |
'<a href="/">Try again</a>'; |
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
20 |
res.send(html); |
bba0504abcf0
added js snippets
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
21 |
}); |