Created
April 29, 2011 05:33
-
-
Save aseemk/947895 to your computer and use it in GitHub Desktop.
Node or Connect bug: form decoding / body parsing
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 express = require('express'); | |
var app = express.createServer(); | |
app.set('views', __dirname); | |
app.set('view engine', 'html'); | |
app.register('.html', require('ejs')); | |
app.configure(function () { | |
app.use(express.bodyParser()); | |
app.use(express.errorHandler({ | |
dumpExceptions: true, | |
showStack: true | |
})); | |
}); | |
app.get('/', function (req, resp) { | |
resp.render('index.html', { | |
host: req.headers.host, | |
url: req.url | |
}); | |
}); | |
app.post('/', function (req, resp) { | |
resp.render('success.html', { | |
data: req.body | |
}); | |
}); | |
app.listen(8888); | |
console.log('Visit http://localhost:8888/ in your browser.'); |
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
<script> | |
function bookmarklet() { | |
var form = document.createElement('form'); | |
var input = document.createElement('input'); | |
input.type = 'hidden'; | |
input.name = 'title'; | |
input.value = document.title; | |
form.action = 'http://<%= host %><%= url %>'; | |
form.method = 'post'; | |
form.target = '_blank'; | |
form.appendChild(input); | |
document.body.appendChild(form); | |
form.submit(); | |
} | |
</script> | |
<p>Drag this bookmarklet up to your bookmarks bar:</p> | |
<p> | |
<script> | |
document.write('<a href="javascript:(' + bookmarklet + ')();">Test</a>'); | |
</script> | |
</p> | |
<p> | |
Then click it from any of these Amazon pages: | |
</p> | |
<ul> | |
<li><a href="http://www.amazon.com/gp/product/B001U0HAZM"> | |
The Machinist</a></li> | |
<li><a href="http://www.amazon.com/Family-Guy-Presents-Stewie-Griffin/dp/B000A3DFV8/ref=pd_cp_d_3"> | |
Family Guy Presents Stewie Griffin</a></li> | |
<li><a href="http://www.amazon.com/gp/product/B000VWYJ86"> | |
The Bourne Ultimatum</a></li> | |
<li><a href="http://www.amazon.com/gp/product/B000GGSMB2"> | |
Scarface</a></li> | |
</ul> | |
<p>Does it work? Or do you see an error page?</p> |
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
<!doctype html> | |
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> | |
<title>Node/Connect form decoding bug?</title> | |
</head> | |
<body> | |
<%- body %> | |
</body> | |
</html> |
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
<p>Success! It worked. Here's the data we received:</p> | |
<pre><%= JSON.stringify(data) %></pre> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment