public
Created

Node or Connect bug: form decoding / body parsing

  • Download Gist
app.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
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.');
index.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
<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>
layout.html
HTML
1 2 3 4 5 6 7 8 9 10
<!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>
success.html
HTML
1 2
<p>Success! It worked. Here's the data we received:</p>
<pre><%= JSON.stringify(data) %></pre>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.