I'm using Express to server up a static HTML file profile.html. In the file, I have a simple form. It used to have a file upload in it, but I've reduced it down to just a single text input for simplicity. Here's what it looks like:
<form action="profile.html" method="post" id="foo" enctype="multipart/form-data">
<input type="text" name="foo" value="bar">
<input type="submit">
</form>
When I click the submit button, Chrome shows signs of submitting the form, but it never happens. My Node.js code for profile.html is never run when submitting the form. And if I look at the network tab of Chrome's developer tools, it shows the request as still pending. This is something that worked perfectly when using PHP and Apache, but is failing when using Node.js and Express.
I've looked at countless examples, but I feel like this has to be a configuration problem, not a code problem. What could be preventing the form from being submitted to my service?
EDIT: Here's roughly what my routes are:
//modules, initialization, etc.
var app = express();
app.use(function(req, res, next) {
var data = "";
req.setEncoding("utf8");
req.on("data", function(chunk) {
data += chunk;
});
req.on("end", function() {
req.rawBody = data;
next();
});
});
app.use(express.bodyParser());
//Server up our templated static HTML
app.use("/search.html", search_html.handler);
app.use("/app.html", app_html.handler);
app.use("/login.html", login_html.handler);
app.use("/graph", graph_page.handler);
app.use("/dbrequest", dbrequest_page.handler);
app.use("/profile.html", profile_html.handler);
app.use("/", function(request, response) {
response.redirect("login.html");
});
app.listen(3000);
The combination of your rawBody middleware and bodyParser isn't going to work: your middleware 'exhausts' the stream provided by req entirely, and bodyParser will try to do the same.
But since the stream has already been read and its end event already triggered, bodyParser is going to wait endlessly for an end event that's never going to occur (which also explains why the request gets stuck in a pending state).
If your middleware isn't strictly necessary, just leave it out. If, for some reason, you do need to access the raw body contents, I'm not sure if it can be done without re-implementing bodyParser yourself.