Skip to content

Commit add8ecd

Browse files
author
James Halliday
committed
networks example server
1 parent 4d71cb2 commit add8ecd

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

networks/package.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"dependencies": {
3+
"body": "^4.5.0",
4+
"ecstatic": "~0.5.8"
5+
}
6+
}

networks/server.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
var ecstatic = require('ecstatic');
12
var http = require('http');
2-
var parseform = require('body/any');
3-
4-
var server = http.createServer(function (req, res) {
5-
parseform(req, res, function (err, params) {
6-
console.log(params);
7-
res.end('ok\n');
8-
});
9-
});
10-
server.listen(5000);
3+
var parseform = require('body/any');
4+
var st = ecstatic(__dirname + '/static');
5+
6+
var server = http.createServer(function (req, res) {
7+
if (req.method === 'POST') {
8+
parseform(req, res, function (err, params) {
9+
console.log(params);
10+
res.end('ok\n');
11+
});
12+
}
13+
else st(req, res)
14+
});
15+
server.listen(5000);

networks/static/index.html

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<form method="POST" action="/wow">
2+
so <input type="text" name="so">
3+
<br>
4+
such <input type="text" name="such">
5+
<br>
6+
<input type="submit" value="very submit">
7+
</form>

0 commit comments

Comments
 (0)