Created
November 6, 2012 06:42
-
-
Save michaelcolenso/4023072 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var qs = require('querystring'); | |
require('http').createServer(function (req, res) { | |
if('/' === req.url) { | |
res.writeHead(200, { 'Content-Type': 'text/html' }); | |
res.end([ | |
'<form method="POST" action="/url">' | |
, '<h1>form it, bro.</h1>' | |
, '<fieldset>' | |
, '<label>personal info</label>' | |
, '<p>who are you, anyway?</p>' | |
, '<input type="text" name="name">' | |
, '<p><button>Submit</button></p>' | |
, '</form>' | |
].join('')); | |
} else if ('/url' === req.url && 'POST' === req.method) { | |
var body = ''; | |
req.on('data', function (chunk) { | |
body += chunk; | |
}); | |
req.on('end', function () { | |
res.writeHead(200, { 'Content-Type': 'text/html' }); | |
res.end('<h2>your name is <b>' + qs.parse(body).name + '</b></h2>'); | |
}); | |
} else { | |
res.writeHead(404); | |
res.end('Not Found'); | |
} | |
}).listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment