Skip to content

Instantly share code, notes, and snippets.

@michaelcolenso
Created November 6, 2012 06:42
Show Gist options
  • Save michaelcolenso/4023072 to your computer and use it in GitHub Desktop.
Save michaelcolenso/4023072 to your computer and use it in GitHub Desktop.
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